Merge "Make UnsafeTag self registering"
This commit is contained in:
commit
29bdc54278
|
@ -27,6 +27,8 @@ except ImportError:
|
|||
|
||||
class UnsafeTag(yaml.YAMLObject):
|
||||
yaml_tag = u'!unsafe'
|
||||
yaml_dumper = yaml.SafeDumper
|
||||
yaml_loader = yaml.SafeLoader
|
||||
|
||||
def __init__(self, unsafe_var):
|
||||
self.unsafe_var = unsafe_var
|
||||
|
@ -43,13 +45,6 @@ class UnsafeTag(yaml.YAMLObject):
|
|||
return self.unsafe_var
|
||||
|
||||
|
||||
# Just calling SafeLoader and SafeDumper without yaml module prefix
|
||||
# does not work and cyaml is using yaml.SafeConstructor yaml.SafeRepresenter
|
||||
# underneath so this just fine for both
|
||||
yaml.SafeLoader.add_constructor(UnsafeTag.yaml_tag, UnsafeTag.from_yaml)
|
||||
yaml.SafeDumper.add_multi_representer(UnsafeTag, UnsafeTag.to_yaml)
|
||||
|
||||
|
||||
def safe_load(stream, *args, **kwargs):
|
||||
return yaml.load(stream, *args, Loader=SafeLoader, **kwargs)
|
||||
|
||||
|
|
Loading…
Reference in New Issue