Skip to content

Commit a001f27

Browse files
committed
Per suggestion #420 (comment) move a few constructors from full_load to unsafe_load.
1 parent fe15062 commit a001f27

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

lib/yaml/constructor.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -722,18 +722,6 @@ def construct_python_object_new(self, suffix, node):
722722
u'tag:yaml.org,2002:python/name:',
723723
FullConstructor.construct_python_name)
724724

725-
FullConstructor.add_multi_constructor(
726-
u'tag:yaml.org,2002:python/module:',
727-
FullConstructor.construct_python_module)
728-
729-
FullConstructor.add_multi_constructor(
730-
u'tag:yaml.org,2002:python/object:',
731-
FullConstructor.construct_python_object)
732-
733-
FullConstructor.add_multi_constructor(
734-
u'tag:yaml.org,2002:python/object/new:',
735-
FullConstructor.construct_python_object_new)
736-
737725
class UnsafeConstructor(FullConstructor):
738726

739727
def find_python_module(self, name, mark):
@@ -750,6 +738,18 @@ def set_python_instance_state(self, instance, state):
750738
return super(UnsafeConstructor, self).set_python_instance_state(
751739
instance, state, unsafe=True)
752740

741+
UnsafeConstructor.add_multi_constructor(
742+
u'tag:yaml.org,2002:python/module:',
743+
UnsafeConstructor.construct_python_module)
744+
745+
UnsafeConstructor.add_multi_constructor(
746+
u'tag:yaml.org,2002:python/object:',
747+
UnsafeConstructor.construct_python_object)
748+
749+
UnsafeConstructor.add_multi_constructor(
750+
u'tag:yaml.org,2002:python/object/new:',
751+
UnsafeConstructor.construct_python_object_new)
752+
753753
UnsafeConstructor.add_multi_constructor(
754754
u'tag:yaml.org,2002:python/object/apply:',
755755
UnsafeConstructor.construct_python_object_apply)

lib3/yaml/constructor.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -710,18 +710,6 @@ def construct_python_object_new(self, suffix, node):
710710
'tag:yaml.org,2002:python/name:',
711711
FullConstructor.construct_python_name)
712712

713-
FullConstructor.add_multi_constructor(
714-
'tag:yaml.org,2002:python/module:',
715-
FullConstructor.construct_python_module)
716-
717-
FullConstructor.add_multi_constructor(
718-
'tag:yaml.org,2002:python/object:',
719-
FullConstructor.construct_python_object)
720-
721-
FullConstructor.add_multi_constructor(
722-
'tag:yaml.org,2002:python/object/new:',
723-
FullConstructor.construct_python_object_new)
724-
725713
class UnsafeConstructor(FullConstructor):
726714

727715
def find_python_module(self, name, mark):
@@ -738,6 +726,18 @@ def set_python_instance_state(self, instance, state):
738726
return super(UnsafeConstructor, self).set_python_instance_state(
739727
instance, state, unsafe=True)
740728

729+
UnsafeConstructor.add_multi_constructor(
730+
'tag:yaml.org,2002:python/module:',
731+
UnsafeConstructor.construct_python_module)
732+
733+
UnsafeConstructor.add_multi_constructor(
734+
'tag:yaml.org,2002:python/object:',
735+
UnsafeConstructor.construct_python_object)
736+
737+
UnsafeConstructor.add_multi_constructor(
738+
'tag:yaml.org,2002:python/object/new:',
739+
UnsafeConstructor.construct_python_object_new)
740+
741741
UnsafeConstructor.add_multi_constructor(
742742
'tag:yaml.org,2002:python/object/apply:',
743743
UnsafeConstructor.construct_python_object_apply)

tests/lib/test_recursive.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_recursive(recursive_filename, verbose=False):
3030
output2 = None
3131
try:
3232
output1 = yaml.dump(value1)
33-
value2 = yaml.load(output1, yaml.FullLoader)
33+
value2 = yaml.load(output1, yaml.UnsafeLoader)
3434
output2 = yaml.dump(value2)
3535
assert output1 == output2, (output1, output2)
3636
finally:

tests/lib3/test_recursive.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def test_recursive(recursive_filename, verbose=False):
3131
output2 = None
3232
try:
3333
output1 = yaml.dump(value1)
34-
value2 = yaml.full_load(output1)
34+
value2 = yaml.unsafe_load(output1)
3535
output2 = yaml.dump(value2)
3636
assert output1 == output2, (output1, output2)
3737
finally:

0 commit comments

Comments
 (0)