Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def dumps(self, cnf, **kwargs):
"""
Dump config 'cnf' to a string.
:param cnf: Configuration data to dump
:param kwargs: optional keyword parameters to be sanitized :: dict
:return: string represents the configuration
"""
kwargs = anyconfig.utils.filter_options(self._dump_opts, kwargs)
return self.dump_to_string(cnf, **kwargs)
def _load_options(self, container, **options):
"""
:param container: callble to make a container object later
"""
if "codec_options" not in options:
options.setdefault("document_class", container)
if any(k in options for k in _CO_OPTIONS):
options["codec_options"] = _codec_options(**options)
return anyconfig.utils.filter_options(self._load_opts, options)
def yml_fnc(fname, *args, **options):
"""
:param fname:
"load" or "dump", not checked but it should be OK.
see also :func:`yml_load` and :func:`yml_dump`
:param args: [stream] for load or [cnf, stream] for dump
:param options: keyword args may contain "ac_safe" to load/dump safely
"""
options = common.filter_from_options("ac_dict", options)
if "ac_safe" in options:
options["typ"] = "safe" # Override it.
iopts = anyconfig.utils.filter_options(_YAML_INIT_KWARGS, options)
oopts = anyconfig.utils.filter_options(_YAML_INSTANCE_MEMBERS, options)
yml = ryaml.YAML(**iopts)
for attr, val in oopts.items():
setattr(yml, attr, val) # e.g. yml.preserve_quotes = True
return getattr(yml, fname)(*args)
def _codec_options(**options):
"""
bson.BSON.{decode{,_all},encode} can receive bson.CodecOptions.
:return: :class:`~bson.CodecOptions`
"""
opts = anyconfig.utils.filter_options(_CO_OPTIONS, options)
return bson.CodecOptions(**opts)
def _make_parser(**kwargs):
"""
:return: (keyword args to be used, parser object)
"""
# Optional arguements for configparser.SafeConfigParser{,readfp}
kwargs_0 = filter_options(("defaults", "dict_type", "allow_no_value"),
kwargs)
kwargs_1 = filter_options(("filename", ), kwargs)
try:
parser = configparser.SafeConfigParser(**kwargs_0)
except TypeError:
# .. note::
# It seems ConfigParser.*ConfigParser in python 2.6 does not support
# 'allow_no_value' option parameter, and TypeError will be thrown.
kwargs_0 = filter_options(("defaults", "dict_type"), kwargs)
parser = configparser.SafeConfigParser(**kwargs_0)
return (kwargs_1, parser)
def _load_options(self, container, **options):
"""
Select backend specific loading options.
"""
# Force set dict option if available in backend. For example,
# options["object_hook"] will be OrderedDict if 'container' was
# OrderedDict in JSON backend.
for opt in self.dict_options():
options.setdefault(opt, container)
return anyconfig.utils.filter_options(self._load_opts, options)
def yml_fnc(fname, *args, **options):
"""
:param fname:
"load" or "dump", not checked but it should be OK.
see also :func:`yml_load` and :func:`yml_dump`
:param args: [stream] for load or [cnf, stream] for dump
:param options: keyword args may contain "ac_safe" to load/dump safely
"""
options = common.filter_from_options("ac_dict", options)
if "ac_safe" in options:
options["typ"] = "safe" # Override it.
iopts = anyconfig.utils.filter_options(_YAML_INIT_KWARGS, options)
oopts = anyconfig.utils.filter_options(_YAML_INSTANCE_MEMBERS, options)
yml = ryaml.YAML(**iopts)
for attr, val in oopts.items():
setattr(yml, attr, val) # e.g. yml.preserve_quotes = True
return getattr(yml, fname)(*args)