File: yamlobjects.py

package info (click to toggle)
python-shopifyapi 12.7.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 560 kB
  • sloc: python: 1,752; sh: 10; makefile: 9
file content (19 lines) | stat: -rw-r--r-- 681 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
try:
    # Shopify serializes receipts in YAML format, and yaml.safe_load will
    # not automatically load custom types because of security purpose,
    # so create safe loaders for types returned from Shopify here.
    #
    # The YAMLObject metaclass will automatically add these classes to
    # the list of constructors for yaml.safe_load to use.
    import yaml

    class YAMLHashWithIndifferentAccess(yaml.YAMLObject):
        yaml_tag = "!map:ActiveSupport::HashWithIndifferentAccess"
        yaml_loader = yaml.SafeLoader

        @classmethod
        def from_yaml(cls, loader, node):
            return loader.construct_mapping(node, cls)

except ImportError:
    pass