-
Notifications
You must be signed in to change notification settings - Fork 518
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change default loader for yaml.add_constructor (#287)
* Change default loader for yaml.add_constructor If the Loader parameter is not given, add constructor to all three loaders
- Loading branch information
Showing
2 changed files
with
28 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -329,22 +329,32 @@ def add_path_resolver(tag, path, kind=None, Loader=Loader, Dumper=Dumper): | |
Loader.add_path_resolver(tag, path, kind) | ||
Dumper.add_path_resolver(tag, path, kind) | ||
|
||
def add_constructor(tag, constructor, Loader=Loader): | ||
def add_constructor(tag, constructor, Loader=None): | ||
""" | ||
Add a constructor for the given tag. | ||
Constructor is a function that accepts a Loader instance | ||
and a node object and produces the corresponding Python object. | ||
""" | ||
Loader.add_constructor(tag, constructor) | ||
if Loader == None: | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
perlpunk
Author
Member
|
||
loader.Loader.add_constructor(tag, constructor) | ||
loader.FullLoader.add_constructor(tag, constructor) | ||
loader.UnsafeLoader.add_constructor(tag, constructor) | ||
else: | ||
Loader.add_constructor(tag, constructor) | ||
|
||
def add_multi_constructor(tag_prefix, multi_constructor, Loader=Loader): | ||
def add_multi_constructor(tag_prefix, multi_constructor, Loader=None): | ||
""" | ||
Add a multi-constructor for the given tag prefix. | ||
Multi-constructor is called for a node if its tag starts with tag_prefix. | ||
Multi-constructor accepts a Loader instance, a tag suffix, | ||
and a node object and produces the corresponding Python object. | ||
""" | ||
Loader.add_multi_constructor(tag_prefix, multi_constructor) | ||
if Loader == None: | ||
loader.Loader.add_multi_constructor(tag_prefix, multi_constructor) | ||
loader.FullLoader.add_multi_constructor(tag_prefix, multi_constructor) | ||
loader.UnsafeLoader.add_multi_constructor(tag_prefix, multi_constructor) | ||
else: | ||
Loader.add_multi_constructor(tag_prefix, multi_constructor) | ||
|
||
def add_representer(data_type, representer, Dumper=Dumper): | ||
""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
isn't it better to use
if Loader is None
comparison or even more simpleif not Loader
?