Skip to content

Commit

Permalink
Add support for anchors/references. And bump version.
Browse files Browse the repository at this point in the history
  • Loading branch information
wimglenn committed Feb 26, 2018
1 parent fc283f4 commit ab19d35
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
18 changes: 11 additions & 7 deletions oyaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,27 @@
import yaml as pyyaml


_viewitems = 'viewitems' if sys.version_info < (3,) else 'items'
_items = 'viewitems' if sys.version_info < (3,) else 'items'


def _representer(dumper, data):
return dumper.represent_dict(getattr(data, _viewitems)())
def map_representer(dumper, data):
return dumper.represent_dict(getattr(data, _items)())


def _constructor(loader, node):
def map_constructor(loader, node):
loader.flatten_mapping(node)
return OrderedDict(loader.construct_pairs(node))


pyyaml.add_representer(dict, _representer)
pyyaml.add_representer(OrderedDict, _representer)
pyyaml.add_representer(dict, map_representer)
pyyaml.add_representer(OrderedDict, map_representer)


if sys.version_info < (3, 7):
pyyaml.add_constructor(pyyaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG, _constructor)
pyyaml.add_constructor('tag:yaml.org,2002:map', map_constructor)


del map_constructor, map_representer


# Merge PyYAML namespace into ours.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='oyaml',
version='0.1',
version='0.2',
description='Ordered YAML: drop-in replacement for PyYAML which preserves dict ordering',
author='Wim Glenn',
author_email='hey@wimglenn.com',
Expand Down

0 comments on commit ab19d35

Please sign in to comment.