diff options
author | Anthon van der Neut <anthon@mnt.org> | 2015-06-21 10:12:48 +0200 |
---|---|---|
committer | Anthon van der Neut <anthon@mnt.org> | 2015-06-21 10:12:48 +0200 |
commit | c82ca710c4c57d1aebee258585216d0fa0eef8ca (patch) | |
tree | bdf7ce47d081c0ad7e22b0d186827f7de11c8b12 | |
parent | 9eff8b0d2e19b45a367dcbb2af0268473d776659 (diff) | |
download | ruamel.yaml-c82ca710c4c57d1aebee258585216d0fa0eef8ca.tar.gz |
- add normal merge processing to RoundTripLoader
-rw-r--r-- | py/constructor.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/py/constructor.py b/py/constructor.py index 0cc86e3..0b9491c 100644 --- a/py/constructor.py +++ b/py/constructor.py @@ -199,6 +199,11 @@ class SafeConstructor(BaseConstructor): return BaseConstructor.construct_scalar(self, node) def flatten_mapping(self, node): + """ + This implements the merge key feature http://yaml.org/type/merge.html + by inserting keys from the merge dict/list of dicts if not yet + available in this node + """ merge = [] index = 0 while index < len(node.value): @@ -245,6 +250,7 @@ class SafeConstructor(BaseConstructor): self.construct_scalar(node) return None + # YAML 1.2 spec doesn't mention yes/no etc any more, 1.1 does bool_values = { u'yes': True, u'no': False, @@ -841,6 +847,8 @@ class RoundTripConstructor(SafeConstructor): None, None, "expected a mapping node, but found %s" % node.id, node.start_mark) + if isinstance(node, MappingNode): + self.flatten_mapping(node) # mapping = {} if node.comment: maptyp._yaml_add_comment(node.comment[:2]) |