MCPcopy Create free account
hub / github.com/DragonisCV/RAM / ordered_yaml

Function ordered_yaml

ram/utils/options.py:13–35  ·  view source on GitHub ↗

Support OrderedDict for yaml. Returns: tuple: yaml Loader and Dumper.

()

Source from the content-addressed store, hash-verified

11from copy import deepcopy
12
13def ordered_yaml():
14 """Support OrderedDict for yaml.
15
16 Returns:
17 tuple: yaml Loader and Dumper.
18 """
19 try:
20 from yaml import CDumper as Dumper
21 from yaml import CLoader as Loader
22 except ImportError:
23 from yaml import Dumper, Loader
24
25 _mapping_tag = yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG
26
27 def dict_representer(dumper, data):
28 return dumper.represent_dict(data.items())
29
30 def dict_constructor(loader, node):
31 return OrderedDict(loader.construct_pairs(node))
32
33 Dumper.add_representer(OrderedDict, dict_representer)
34 Loader.add_constructor(_mapping_tag, dict_constructor)
35 return Loader, Dumper
36
37
38def yaml_load(f):

Callers 1

yaml_loadFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected