summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTina Müller <cpan2@tinita.de>2019-06-11 22:53:40 +0200
committerTina Müller <cpan2@tinita.de>2019-11-18 12:02:04 +0100
commit9f6581baa307f11d7ffff14aea16ef86f6af5702 (patch)
tree4b91d6029a43880eb5bb8385b362f6783280b484
parent0f64cbfa54b0b22dc7b776b7b98a7cd657e84d78 (diff)
downloadpyyaml-git-perlpunk/default-loader.tar.gz
Change default loader for add_implicit_resolver, add_path_resolverperlpunk/default-loader
If the Loader parameter is not given, add constructor to all three loaders
-rw-r--r--lib/yaml/__init__.py18
-rw-r--r--lib3/yaml/__init__.py18
2 files changed, 28 insertions, 8 deletions
diff --git a/lib/yaml/__init__.py b/lib/yaml/__init__.py
index 5d56d65..fd89a99 100644
--- a/lib/yaml/__init__.py
+++ b/lib/yaml/__init__.py
@@ -309,24 +309,34 @@ def safe_dump(data, stream=None, **kwds):
return dump_all([data], stream, Dumper=SafeDumper, **kwds)
def add_implicit_resolver(tag, regexp, first=None,
- Loader=Loader, Dumper=Dumper):
+ Loader=None, Dumper=Dumper):
"""
Add an implicit scalar detector.
If an implicit scalar value matches the given regexp,
the corresponding tag is assigned to the scalar.
first is a sequence of possible initial characters or None.
"""
- Loader.add_implicit_resolver(tag, regexp, first)
+ if Loader is None:
+ loader.Loader.add_implicit_resolver(tag, regexp, first)
+ loader.FullLoader.add_implicit_resolver(tag, regexp, first)
+ loader.UnsafeLoader.add_implicit_resolver(tag, regexp, first)
+ else:
+ Loader.add_implicit_resolver(tag, regexp, first)
Dumper.add_implicit_resolver(tag, regexp, first)
-def add_path_resolver(tag, path, kind=None, Loader=Loader, Dumper=Dumper):
+def add_path_resolver(tag, path, kind=None, Loader=None, Dumper=Dumper):
"""
Add a path based resolver for the given tag.
A path is a list of keys that forms a path
to a node in the representation tree.
Keys can be string values, integers, or None.
"""
- Loader.add_path_resolver(tag, path, kind)
+ if Loader is None:
+ loader.Loader.add_path_resolver(tag, path, kind)
+ loader.FullLoader.add_path_resolver(tag, path, kind)
+ loader.UnsafeLoader.add_path_resolver(tag, path, kind)
+ else:
+ Loader.add_path_resolver(tag, path, kind)
Dumper.add_path_resolver(tag, path, kind)
def add_constructor(tag, constructor, Loader=Loader):
diff --git a/lib3/yaml/__init__.py b/lib3/yaml/__init__.py
index 3f499d3..1b35282 100644
--- a/lib3/yaml/__init__.py
+++ b/lib3/yaml/__init__.py
@@ -306,24 +306,34 @@ def safe_dump(data, stream=None, **kwds):
return dump_all([data], stream, Dumper=SafeDumper, **kwds)
def add_implicit_resolver(tag, regexp, first=None,
- Loader=Loader, Dumper=Dumper):
+ Loader=None, Dumper=Dumper):
"""
Add an implicit scalar detector.
If an implicit scalar value matches the given regexp,
the corresponding tag is assigned to the scalar.
first is a sequence of possible initial characters or None.
"""
- Loader.add_implicit_resolver(tag, regexp, first)
+ if Loader is None:
+ loader.Loader.add_implicit_resolver(tag, regexp, first)
+ loader.FullLoader.add_implicit_resolver(tag, regexp, first)
+ loader.UnsafeLoader.add_implicit_resolver(tag, regexp, first)
+ else:
+ Loader.add_implicit_resolver(tag, regexp, first)
Dumper.add_implicit_resolver(tag, regexp, first)
-def add_path_resolver(tag, path, kind=None, Loader=Loader, Dumper=Dumper):
+def add_path_resolver(tag, path, kind=None, Loader=None, Dumper=Dumper):
"""
Add a path based resolver for the given tag.
A path is a list of keys that forms a path
to a node in the representation tree.
Keys can be string values, integers, or None.
"""
- Loader.add_path_resolver(tag, path, kind)
+ if Loader is None:
+ loader.Loader.add_path_resolver(tag, path, kind)
+ loader.FullLoader.add_path_resolver(tag, path, kind)
+ loader.UnsafeLoader.add_path_resolver(tag, path, kind)
+ else:
+ Loader.add_path_resolver(tag, path, kind)
Dumper.add_path_resolver(tag, path, kind)
def add_constructor(tag, constructor, Loader=Loader):