Skip to content

Commit 9f6581b

Browse files
committed
Change default loader for add_implicit_resolver, add_path_resolver
If the Loader parameter is not given, add constructor to all three loaders
1 parent 0f64cbf commit 9f6581b

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

lib/yaml/__init__.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,24 +309,34 @@ def safe_dump(data, stream=None, **kwds):
309309
return dump_all([data], stream, Dumper=SafeDumper, **kwds)
310310

311311
def add_implicit_resolver(tag, regexp, first=None,
312-
Loader=Loader, Dumper=Dumper):
312+
Loader=None, Dumper=Dumper):
313313
"""
314314
Add an implicit scalar detector.
315315
If an implicit scalar value matches the given regexp,
316316
the corresponding tag is assigned to the scalar.
317317
first is a sequence of possible initial characters or None.
318318
"""
319-
Loader.add_implicit_resolver(tag, regexp, first)
319+
if Loader is None:
320+
loader.Loader.add_implicit_resolver(tag, regexp, first)
321+
loader.FullLoader.add_implicit_resolver(tag, regexp, first)
322+
loader.UnsafeLoader.add_implicit_resolver(tag, regexp, first)
323+
else:
324+
Loader.add_implicit_resolver(tag, regexp, first)
320325
Dumper.add_implicit_resolver(tag, regexp, first)
321326

322-
def add_path_resolver(tag, path, kind=None, Loader=Loader, Dumper=Dumper):
327+
def add_path_resolver(tag, path, kind=None, Loader=None, Dumper=Dumper):
323328
"""
324329
Add a path based resolver for the given tag.
325330
A path is a list of keys that forms a path
326331
to a node in the representation tree.
327332
Keys can be string values, integers, or None.
328333
"""
329-
Loader.add_path_resolver(tag, path, kind)
334+
if Loader is None:
335+
loader.Loader.add_path_resolver(tag, path, kind)
336+
loader.FullLoader.add_path_resolver(tag, path, kind)
337+
loader.UnsafeLoader.add_path_resolver(tag, path, kind)
338+
else:
339+
Loader.add_path_resolver(tag, path, kind)
330340
Dumper.add_path_resolver(tag, path, kind)
331341

332342
def add_constructor(tag, constructor, Loader=Loader):

lib3/yaml/__init__.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,24 +306,34 @@ def safe_dump(data, stream=None, **kwds):
306306
return dump_all([data], stream, Dumper=SafeDumper, **kwds)
307307

308308
def add_implicit_resolver(tag, regexp, first=None,
309-
Loader=Loader, Dumper=Dumper):
309+
Loader=None, Dumper=Dumper):
310310
"""
311311
Add an implicit scalar detector.
312312
If an implicit scalar value matches the given regexp,
313313
the corresponding tag is assigned to the scalar.
314314
first is a sequence of possible initial characters or None.
315315
"""
316-
Loader.add_implicit_resolver(tag, regexp, first)
316+
if Loader is None:
317+
loader.Loader.add_implicit_resolver(tag, regexp, first)
318+
loader.FullLoader.add_implicit_resolver(tag, regexp, first)
319+
loader.UnsafeLoader.add_implicit_resolver(tag, regexp, first)
320+
else:
321+
Loader.add_implicit_resolver(tag, regexp, first)
317322
Dumper.add_implicit_resolver(tag, regexp, first)
318323

319-
def add_path_resolver(tag, path, kind=None, Loader=Loader, Dumper=Dumper):
324+
def add_path_resolver(tag, path, kind=None, Loader=None, Dumper=Dumper):
320325
"""
321326
Add a path based resolver for the given tag.
322327
A path is a list of keys that forms a path
323328
to a node in the representation tree.
324329
Keys can be string values, integers, or None.
325330
"""
326-
Loader.add_path_resolver(tag, path, kind)
331+
if Loader is None:
332+
loader.Loader.add_path_resolver(tag, path, kind)
333+
loader.FullLoader.add_path_resolver(tag, path, kind)
334+
loader.UnsafeLoader.add_path_resolver(tag, path, kind)
335+
else:
336+
Loader.add_path_resolver(tag, path, kind)
327337
Dumper.add_path_resolver(tag, path, kind)
328338

329339
def add_constructor(tag, constructor, Loader=Loader):

0 commit comments

Comments
 (0)