Parse 'python class key="value"' into [('python', None), ('class', None), ('key', 'value')]
496338
def parse_md_code_options(options):
    """"""

    metadata = []
    while options:
        name_and_value = re.split(r'[\s=]+', options, maxsplit=1)
        name = name_and_value[0]

        # Equal sign in between name and what's next?
        if len(name_and_value) == 2:
            sep = options[len(name):-len(name_and_value[1])]
            has_value = sep.find('=') >= 0
            options = name_and_value[1]
        else:
            has_value = False
            options = ''

        if not has_value:
            metadata.append((name, None))
            continue

        try:
            value = loads(options)
            options = ''
        except JSONDecodeError as err:
            try:
                split = err.colno - 1
            except AttributeError:
                # str(err) is like: "ValueError: Extra data: line 1 column 7 - line 1 column 50 (char 6 - 49)"
                match = re.match(r'.*char ([0-9]*)', str(err))
                split = int(match.groups()[0])

            value = loads(options[:split])
            options = options[split:]

        metadata.append((name, value))

    return metadata
1226099
def parse_attributes(attributes=None, classname=None):
  
  if not attributes:
    attributes = {}
  attributes.setdefault('class', DEFAULT_CLASS_NAME)
  # If `classname` is specified, it overwrites `class` property in `attributes`.
  if classname:
    attributes['class'] = classname
  return attributes
531162
def parse(self, value):
        
        if self.required and value is None:
            raise ValueError("%s is required!" % self.name)
        elif self.ignored and value is not None:
            warn("%s is ignored for this class!" % self.name)
        elif not self.multi and isinstance(value, (list, tuple)):
            if len(value) > 1:
                raise ValueError(
                    "%s does not accept multiple values!" % self.name
                )
            return value[0]
        elif self.multi and value is not None:
            if not isinstance(value, (list, tuple)):
                return [value]
        return value
96614
def _from_dict(cls, values, value_filter, dictionary, allow_unset=True):
        """"""
        if not isinstance(dictionary, Mapping):
            raise TypeError('dictionary should be mapping')
        obj = cls(values, value_filter)
        values = obj.__values
        for name, value in dictionary.items():
            if not isinstance(name, string_types):
                raise TypeError('Key %s is not a string' % str(name))
            setattr(values, name, value)
        if obj.missing and not allow_unset:
            raise ValueError('%d value(s) are unset' % len(obj.missing))
        return obj
360429
def kw_str_parse(a_string):
    """"""
    try:
        return dict((k, eval(v.rstrip(',')))
                    for k, v in kw_list_re.findall(a_string))
    except (AttributeError, TypeError):
        if isinstance(a_string, collections.Mapping):
            return a_string
        return {}
638203
def _parse(cls, data, key=None):
        
        parse = cls.parse if cls.parse is not None else cls.get_endpoint()

        if callable(parse):
            data = parse(data)
        elif isinstance(parse, str):
            data = data[key]
        else:
            raise Exception('"parse" should be a callable or string got, {0}'
                            .format(parse))
        return data
644955
def _parse_codeargs(argstr):
    '''
    
    '''
    args = []
    kwargs = {}
    if isinstance(argstr, str):
        for a in argstr.split():
            if '=' in a:
                k,attr = a.split('=')
                kwargs[k] = attr
            else:
                args.append(a)
    rd = {'args':args, 'kwargs':kwargs}
    return rd
667500
def _parse_dict_string(self, string, key, default):
        """"""
        try:
            for item in string.split(','):
                k, v = item.rsplit('=', 1)
                if k == key:
                    try:
                        return int(v)
                    except ValueError:
                        return v
            return default
        except Exception:
            self.log.exception("Cannot parse dictionary string: %s" % string)
            return default
651892
def fromkeys(cls, iterable, value, **kwargs):
        
        return cls(((k, value) for k in iterable), **kwargs)
1286307
def parse_input(args, kwargs=None, condition=True, no_parse=None):
    '''
    
    '''
    if no_parse is None:
        no_parse = ()
    if kwargs is None:
        kwargs = {}
    _args = []
    _kwargs = {}
    for arg in args:
        if isinstance(arg, six.string_types):
            arg_name, arg_value = parse_kwarg(arg)
            if arg_name:
                _kwargs[arg_name] = yamlify_arg(arg_value) \
                    if arg_name not in no_parse \
                    else arg_value
            else:
                _args.append(yamlify_arg(arg))
        elif isinstance(arg, dict):
            # Yes, we're popping this key off and adding it back if
            # condition_input is called below, but this is the only way to
            # gracefully handle both CLI and API input.
            if arg.pop('__kwarg__', False) is True:
                _kwargs.update(arg)
            else:
                _args.append(arg)
        else:
            _args.append(arg)
    _kwargs.update(kwargs)
    if condition:
        return condition_input(_args, _kwargs)
    return _args, _kwargs
159506
def get_class(class_string):
    
    split_string = class_string.encode('ascii').split('.')
    import_path = '.'.join(split_string[:-1])
    class_name = split_string[-1]

    if class_name:
        try:
            if import_path:
                mod = __import__(import_path, globals(), {}, [class_name])
                cls = getattr(mod, class_name)
            else:
                cls = __import__(class_name, globals(), {})
            if cls:
                return cls
        except (ImportError, AttributeError):
            pass

    return None
1270626
def decode(cls, value):
        
        try:
            return None if value is None else \
                list(json.loads(value.decode(cls._encoding)))
        except (TypeError, AttributeError):
            return list(value)
228119
def to_python(self, value):
        ""
        # Return None if no input was given.
        if not value:
            return []
        return [v.strip() for v in value.splitlines() if v != ""]
941674
def parse_options(**kwargs):
    """"""
    return {camelize(key): value
            for key, value in kwargs.items()
            if value is not None}
766832
def parse_class(val):
    
    module, class_name = val.rsplit('.', 1)
    module = importlib.import_module(module)
    try:
        return getattr(module, class_name)
    except AttributeError:
        raise ValueError('"%s" is not a valid member of %s' % (
            class_name, qualname(module))
        )
694625
def parse_class_names(args):
    
    num_class = args.num_class
    if len(args.class_names) > 0:
        if os.path.isfile(args.class_names):
            # try to open it to read class names
            with open(args.class_names, 'r') as f:
                class_names = [l.strip() for l in f.readlines()]
        else:
            class_names = [c.strip() for c in args.class_names.split(',')]
        assert len(class_names) == num_class, str(len(class_names))
        for name in class_names:
            assert len(name) > 0
    else:
        class_names = None
    return class_names
1277415
def from_dict(cls, val):
        
        if isinstance(val, dict2):
            return val

        elif isinstance(val, dict):
            res = cls()
            for k, v in val.items():
                res[k] = cls.from_dict(v)
            return res

        elif isinstance(val, list):
            res = []
            for item in val:
                res.append(cls.from_dict(item))
            return res
        else:
            return val