Skip to content

Commit

Permalink
Add experimental wrappers around YAML 1.2 tags code
Browse files Browse the repository at this point in the history
This way people can play with it, and we don't promise this wrapper will stay
around forever, and newly created classes CommonDumper/CommonRepresenter aren't
exposed.

    MyCoreLoader = yaml.experimental_12_Core_loader()
    data = yaml.load(input, Loader=MyCoreLoader)

    MyCoreDumper = yaml.experimental_12_Core_dumper()
    out = yaml.dump(data, Dumper=MyCoreDumper)
  • Loading branch information
perlpunk committed Dec 2, 2023
1 parent b80472f commit 5e41e14
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/yaml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,17 @@ def add_multi_representer(data_type, multi_representer, Dumper=Dumper):
"""
Dumper.add_multi_representer(data_type, multi_representer)

def experimental_12_Core_loader():
return loader._12_CoreLoader
def experimental_12_JSON_loader():
return loader._12_JSONLoader

def experimental_12_Core_dumper():
return dumper._12_CoreDumper
def experimental_12_JSON_dumper():
return dumper._12_JSONDumper
class YAMLObjectMetaclass(type):

"""
The metaclass for YAMLObject.
"""
Expand Down
5 changes: 5 additions & 0 deletions lib/yaml/dumper.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,8 @@ def __init__(self, stream,
default_flow_style=default_flow_style, sort_keys=sort_keys)
Resolver.__init__(self)

class _12_CoreDumper(CommonDumper): pass
_12_CoreDumper.init_tags('core')
class _12_JSONDumper(CommonDumper): pass
_12_JSONDumper.init_tags('json')

6 changes: 6 additions & 0 deletions lib/yaml/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,9 @@ def __init__(self, stream):
Composer.__init__(self)
Constructor.__init__(self)
Resolver.__init__(self)

class _12_CoreLoader(BaseLoader): pass
_12_CoreLoader.init_tags('core')
class _12_JSONLoader(BaseLoader): pass
_12_JSONLoader.init_tags('json')

0 comments on commit 5e41e14

Please sign in to comment.