Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhancement: make ruamel.yaml based backend works w/o PyYAML
Make ruamel.yaml based backend works w/o PyYAML by: - Introduce anyconfig.backend.yaml.common to move common parts from anyconfig.backend.yamlpyyaml - Remove dependency to anyconfig.backend.yaml.pyyaml from anyconfig.backend.yaml.ruamel_yaml and simplify it This enhanement also might close the issue #99.
- Loading branch information
Showing
3 changed files
with
61 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# | ||
# Copyright (C) 2011 - 2018 Satoru SATOH <ssato @ redhat.com> | ||
# Copyright (C) 2019 Satoru SATOH <satoru.satoh@gmail.com> | ||
# License: MIT | ||
# | ||
r"""Common parts for YAML backends: | ||
""" | ||
from __future__ import absolute_import | ||
import anyconfig.backend.base | ||
|
||
|
||
def filter_from_options(key, options): | ||
""" | ||
:param key: Key str in options | ||
:param options: Mapping object | ||
:return: | ||
New mapping object from `options` in which the item with `key` filtered | ||
>>> filter_from_options('a', dict(a=1, b=2)) | ||
{'b': 2} | ||
""" | ||
return anyconfig.utils.filter_options([k for k in options.keys() | ||
if k != key], options) | ||
|
||
|
||
class Parser(anyconfig.backend.base.StreamParser): | ||
""" | ||
Parser for YAML files. | ||
""" | ||
_type = "yaml" | ||
_extensions = ["yaml", "yml"] | ||
_ordered = True | ||
_allow_primitives = True | ||
_dict_opts = ["ac_dict"] | ||
|
||
# vim:sw=4:ts=4:et: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters