def loads(config_content, forced_type=None, **kwargs): """ :param config_content: Configuration file's content :param forced_type: Forced configuration parser type """ if forced_type is None: return P.parse(config_content) cparser = find_loader(None, forced_type) if cparser is None: return P.parse(config_content) return cparser.loads(config_content, **kwargs)
def loads(config_content, forced_type=None, **kwargs): """ :param config_content: Configuration file's content :param forced_type: Forced configuration parser type :param kwargs: Backend specific optional arguments, e.g. {"indent": 2} for JSON loader/dumper backend :return: Dict-like object (instance of anyconfig.mergeabledict.MergeableDict by default) supports merge operations. """ if forced_type is None: return P.parse(config_content) cparser = find_loader(None, forced_type) if cparser is None: return P.parse(config_content) return cparser.loads(config_content, **kwargs)
def _parse(v, sep=_SEP): """ :param v: A string represents some value to parse :param sep: separator between values >>> _parse(r'"foo string"') 'foo string' >>> _parse("a, b, c") ['a', 'b', 'c'] >>> _parse("aaa") 'aaa' """ if (v.startswith('"') and v.endswith('"')) or \ (v.startswith("'") and v.endswith("'")): return v[1:-1] elif sep in v: return [P.parse(x) for x in P.parse_list(v)] else: return P.parse(v)
def _parse(val_s, sep=_SEP): """ FIXME: May be too naive implementation. :param val_s: A string represents some value to parse :param sep: separator between values >>> _parse(r'"foo string"') 'foo string' >>> _parse("a, b, c") ['a', 'b', 'c'] >>> _parse("aaa") 'aaa' """ if (val_s.startswith('"') and val_s.endswith('"')) or \ (val_s.startswith("'") and val_s.endswith("'")): return val_s[1:-1] elif sep in val_s: return [P.parse(x) for x in P.parse_list(val_s)] else: return P.parse(val_s)
def _parse(val_s, sep=_SEP): """ FIXME: May be too naive implementation. :param val_s: A string represents some value to parse :param sep: separator between values >>> _parse(r'"foo string"') 'foo string' >>> _parse("a, b, c") ['a', 'b', 'c'] >>> _parse("aaa") 'aaa' """ if (val_s.startswith('"') and val_s.endswith('"')) or \ (val_s.startswith("'") and val_s.endswith("'")): return val_s[1:-1] if sep in val_s: return [P.parse(x) for x in P.parse_list(val_s)] return P.parse(val_s)