anyconfig.backend.yaml
¶
YAML backend:
- Format to support: YAML, http://yaml.org
- Requirements:
- ruamel.yaml, https://bitbucket.org/ruamel/yaml
- or PyYAML (yaml), http://pyyaml.org
- Development Status :: 5 - Production/Stable
- Limitations:
- Resuls is not ordered even if ‘ac_ordered’ or ‘ac_dict’ was given.
- Special options:
- All keyword options of yaml.safe_load, yaml.load, yaml.safe_dump and yaml.dump should work.
- Use ‘ac_safe’ boolean keyword option if you prefer to call yaml.safe_load and yaml.safe_dump instead of yaml.load and yaml.dump. Please note that this option conflicts with ‘ac_dict’ option and these options cannot be used at the same time.
- See also: http://pyyaml.org/wiki/PyYAMLDocumentation
Changelog:
-
Changed in version 0.9.3:
Try ruamel.yaml instead of yaml (PyYAML) if it’s available.
-
Changed in version 0.3:
Changed special keyword option ‘ac_safe’ from ‘safe’ to avoid possibility of option conflicts in the future.
-
anyconfig.backend.yaml.
_filter_from_options
(key, options)¶ Parameters: - key – Key str in options
- options – Mapping object
Returns: New mapping object from options in which the item with key filtered
>>> _filter_from_options('a', dict(a=1, b=2)) {'b': 2}
-
anyconfig.backend.yaml.
_customized_loader
(container, loader=<class 'yaml.cyaml.CSafeLoader'>, mapping_tag=u'tag:yaml.org, 2002:map')¶ Create or update loader with making given callble container to make mapping objects such as dict and OrderedDict, used to construct python object from yaml mapping node internally.
Parameters: container – Set container used internally
-
anyconfig.backend.yaml.
_customized_dumper
(container, dumper=<class 'yaml.cyaml.CDumper'>)¶ Coutnerpart of
_customized_loader()
for dumpers.
-
anyconfig.backend.yaml.
_yml_fnc
(fname, *args, **options)¶ An wrapper of yaml.safe_load, yaml.load, yaml.safe_dump and yaml.dump.
Parameters: - fname – “load” or “dump”, not checked but it should be OK.
see also
_yml_load()
and_yml_dump()
- args – [stream] for load or [cnf, stream] for dump
- options – keyword args may contain “ac_safe” to load/dump safely
- fname – “load” or “dump”, not checked but it should be OK.
see also
-
anyconfig.backend.yaml.
_yml_load
(stream, container, **options)¶ An wrapper of yaml.safe_load and yaml.load.
Parameters: - stream – a file or file-like object to load YAML content
- container – callble to make a container object
Returns: Mapping object
-
anyconfig.backend.yaml.
_yml_dump
(cnf, stream, **options)¶ An wrapper of yaml.safe_dump and yaml.dump.
Parameters: - cnf – Mapping object to dump
- stream – a file or file-like object to dump YAML data
-
class
anyconfig.backend.yaml.
Parser
¶ Bases:
anyconfig.backend.base.StreamParser
Parser for YAML files.
-
_type
= 'yaml'¶
-
_extensions
= ['yaml', 'yml']¶
-
_load_opts
= ['Loader', 'ac_safe', 'ac_dict']¶
-
_dump_opts
= ['stream', 'ac_safe', 'Dumper', 'default_style', 'default_flow_style', 'canonical', 'indent', 'width', 'allow_unicode', 'line_break', 'encoding', 'explicit_start', 'explicit_end', 'version', 'tags']¶
-
_ordered
= True¶
-
_dict_opts
= ['ac_dict']¶
-
load_from_stream
(*args, **kwargs)¶ An wrapper of yaml.safe_load and yaml.load.
Parameters: - stream – a file or file-like object to load YAML content
- container – callble to make a container object
Returns: Mapping object
-
dump_to_stream
(*args, **kwargs)¶ An wrapper of yaml.safe_dump and yaml.dump.
Parameters: - cnf – Mapping object to dump
- stream – a file or file-like object to dump YAML data
-
__module__
= 'anyconfig.backend.yaml'¶
-