(self, argname, strval, length='*')
return lst
Convert list strings to typed lists.
Convert list strings to typed lists.
Convert list strings to typed lists .
def _to_list(self, argname, strval, length='*'):
        """Convert list strings to typed lists."""
        lst = strval.split(u',')
        if lst == [u'']:
            if length == '*':
                return []
            elif length < 0:
                return [None] * (-length)  # pylint: disable=invalid-unary-operand-type
            else:
                return None
        parsed = (self._parse_type(argname, _arg) for _arg in lst)
        lst = [_arg for _arg in parsed if _arg]
        # negative length: optional up-to
        if length != u'*' and length < 0:
            lst += [None] * (-length-len(lst))  # pylint: disable=invalid-unary-operand-type
        if length != u'*' and (len(lst) > abs(length) or len(lst) < length):
            logging.warning(
                u'Option `%s=%s` ignored: list should have %d elements, found %d',
                argname, strval, abs(length), len(lst)
            )
            lst = []
        if lst and argname in ARGUMENTS and u'listcheck' in ARGUMENTS[argname]:
            if not ARGUMENTS[argname][u'listcheck'](lst):
                logging.warning(u'Value "%s=%s" ignored; invalid', argname, strval)
                lst = []
        return lst
def _to_list ( self , argname , strval , length = '*' ) : lst = strval . split ( u',' ) if lst == [ u'' ] : if length == '*' : return [ ] elif length < 0 : return [ None ] * ( - length ) # pylint: disable=invalid-unary-operand-type else : return None parsed = ( self . _parse_type ( argname , _arg ) for _arg in lst ) lst = [ _arg for _arg in parsed if _arg ] # negative length: optional up-to if length != u'*' and length < 0 : lst += [ None ] * ( - length - len ( lst ) ) # pylint: disable=invalid-unary-operand-type if length != u'*' and ( len ( lst ) > abs ( length ) or len ( lst ) < length ) : logging . warning ( u'Option `%s=%s` ignored: list should have %d elements, found %d' , argname , strval , abs ( length ) , len ( lst ) ) lst = [ ] if lst and argname in ARGUMENTS and u'listcheck' in ARGUMENTS [ argname ] : if not ARGUMENTS [ argname ] [ u'listcheck' ] ( lst ) : logging . warning ( u'Value "%s=%s" ignored; invalid' , argname , strval ) lst = [ ] return lst