Dump an OrderedDict object to yaml. :param to_dump: The OrderedDict to dump :type to_dump: OrderedDict :param stream: The file to dump to If not given or if None, only return the value :type stream: file
(to_dump, stream=None)
| 39 | |
| 40 | |
| 41 | def ordered_yaml_dump(to_dump, stream=None): |
| 42 | """ |
| 43 | Dump an OrderedDict object to yaml. |
| 44 | |
| 45 | :param to_dump: The OrderedDict to dump |
| 46 | :type to_dump: OrderedDict |
| 47 | |
| 48 | :param stream: The file to dump to |
| 49 | If not given or if None, only return the value |
| 50 | :type stream: file |
| 51 | """ |
| 52 | yaml = ruamel.yaml.YAML(typ="safe", pure=True) |
| 53 | yaml.default_flow_style = False |
| 54 | yaml.width = float('inf') |
| 55 | yaml.Representer.add_representer(OrderedDict, _ordered_representer) |
| 56 | |
| 57 | if stream is None: |
| 58 | return dump_yaml_to_str(yaml, to_dump) |
| 59 | |
| 60 | yaml.dump(to_dump, stream) |
no test coverage detected