@@ -65,48 +65,40 @@ def load(stream, Loader=Loader):
65
65
"""
66
66
Parse the first YAML document in a stream
67
67
and produce the corresponding Python object.
68
-
69
- By default resolve only basic YAML tags, if an alternate Loader is
70
- provided, may be dangerous.
71
68
"""
72
69
loader = Loader (stream )
73
70
try :
74
71
return loader .get_single_data ()
75
72
finally :
76
73
loader .dispose ()
77
- safe_load = load
78
74
79
75
def load_all (stream , Loader = Loader ):
80
76
"""
81
77
Parse all YAML documents in a stream
82
78
and produce corresponding Python objects.
83
-
84
- By default resolve only basic YAML tags, if an alternate Loader is
85
- provided, may be dangerous.
86
79
"""
87
80
loader = Loader (stream )
88
81
try :
89
82
while loader .check_data ():
90
83
yield loader .get_data ()
91
84
finally :
92
85
loader .dispose ()
93
- safe_load_all = load_all
94
86
95
- def danger_load (stream ):
87
+ def safe_load (stream ):
96
88
"""
97
89
Parse the first YAML document in a stream
98
90
and produce the corresponding Python object.
99
- When used on untrusted input, can result in arbitrary code execution .
91
+ Resolve only basic YAML tags .
100
92
"""
101
- return load (stream , DangerLoader )
93
+ return load (stream , SafeLoader )
102
94
103
- def danger_load_all (stream ):
95
+ def safe_load_all (stream ):
104
96
"""
105
97
Parse all YAML documents in a stream
106
98
and produce corresponding Python objects.
107
- When used on untrusted input, can result in arbitrary code execution .
99
+ Resolve only basic YAML tags .
108
100
"""
109
- return load_all (stream , DangerLoader )
101
+ return load_all (stream , SafeLoader )
110
102
111
103
def emit (events , stream = None , Dumper = Dumper ,
112
104
canonical = None , indent = None , width = None ,
@@ -201,31 +193,29 @@ def dump_all(documents, stream=None, Dumper=Dumper,
201
193
dumper .dispose ()
202
194
if getvalue :
203
195
return getvalue ()
204
- safe_dump_all = dump_all
205
196
206
- def danger_dump_all ( documents , stream = None , ** kwds ):
197
+ def dump ( data , stream = None , Dumper = Dumper , ** kwds ):
207
198
"""
208
- Serialize a sequence of Python objects into a YAML stream.
209
- Produce only basic YAML tags.
199
+ Serialize a Python object into a YAML stream.
210
200
If stream is None, return the produced string instead.
211
201
"""
212
- return dump_all (documents , stream , Dumper = DangerDumper , ** kwds )
202
+ return dump_all ([ data ] , stream , Dumper = Dumper , ** kwds )
213
203
214
- def dump ( data , stream = None , Dumper = Dumper , ** kwds ):
204
+ def safe_dump_all ( documents , stream = None , ** kwds ):
215
205
"""
216
- Serialize a Python object into a YAML stream.
206
+ Serialize a sequence of Python objects into a YAML stream.
207
+ Produce only basic YAML tags.
217
208
If stream is None, return the produced string instead.
218
209
"""
219
- return dump_all ([data ], stream , Dumper = Dumper , ** kwds )
220
- safe_dump = dump
210
+ return dump_all (documents , stream , Dumper = SafeDumper , ** kwds )
221
211
222
- def danger_dump (data , stream = None , ** kwds ):
212
+ def safe_dump (data , stream = None , ** kwds ):
223
213
"""
224
214
Serialize a Python object into a YAML stream.
225
215
Produce only basic YAML tags.
226
216
If stream is None, return the produced string instead.
227
217
"""
228
- return dump_all ([data ], stream , Dumper = DangerDumper , ** kwds )
218
+ return dump_all ([data ], stream , Dumper = SafeDumper , ** kwds )
229
219
230
220
def add_implicit_resolver (tag , regexp , first = None ,
231
221
Loader = Loader , Dumper = Dumper ):
@@ -322,3 +312,4 @@ def to_yaml(cls, dumper, data):
322
312
return dumper .represent_yaml_object (cls .yaml_tag , data , cls ,
323
313
flow_style = cls .yaml_flow_style )
324
314
to_yaml = classmethod (to_yaml )
315
+
0 commit comments