Skip to content

Commit

Permalink
read_spectrum always parse dictionaries as AttributeDict objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiodsf committed Mar 27, 2024
1 parent 7071570 commit fe05353
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions sourcespec/spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,11 +602,24 @@ def _quoted_representer(dumper, data):
return dumper.represent_scalar('tag:yaml.org,2002:str', data, style="'")


def _dict_constructor(loader, node):
"""
YAML constructor for dictionaries.
:param loader: The YAML loader.
:param node: The node to construct.
:return: The dictionary constructed from the node.
"""
return AttributeDict(loader.construct_mapping(node))


# register the representers
yaml.representer.SafeRepresenter.add_representer(
None, _default_yaml_representer)
_HDF5HeaderDumper.add_representer(str, _quoted_representer)
_HDF5HeaderDumper.add_representer(None, _default_yaml_representer)
# register the constructor
yaml.SafeLoader.add_constructor('tag:yaml.org,2002:map', _dict_constructor)


def _normalize_metadata_object(obj):
Expand Down

0 comments on commit fe05353

Please sign in to comment.