@@ -65,48 +65,40 @@ def load(stream, Loader=Loader):
6565 """
6666 Parse the first YAML document in a stream
6767 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.
7168 """
7269 loader = Loader (stream )
7370 try :
7471 return loader .get_single_data ()
7572 finally :
7673 loader .dispose ()
77- safe_load = load
7874
7975def load_all (stream , Loader = Loader ):
8076 """
8177 Parse all YAML documents in a stream
8278 and produce corresponding Python objects.
83-
84- By default resolve only basic YAML tags, if an alternate Loader is
85- provided, may be dangerous.
8679 """
8780 loader = Loader (stream )
8881 try :
8982 while loader .check_data ():
9083 yield loader .get_data ()
9184 finally :
9285 loader .dispose ()
93- safe_load_all = load_all
9486
95- def danger_load (stream ):
87+ def safe_load (stream ):
9688 """
9789 Parse the first YAML document in a stream
9890 and produce the corresponding Python object.
99- When used on untrusted input, can result in arbitrary code execution .
91+ Resolve only basic YAML tags .
10092 """
101- return load (stream , DangerLoader )
93+ return load (stream , SafeLoader )
10294
103- def danger_load_all (stream ):
95+ def safe_load_all (stream ):
10496 """
10597 Parse all YAML documents in a stream
10698 and produce corresponding Python objects.
107- When used on untrusted input, can result in arbitrary code execution .
99+ Resolve only basic YAML tags .
108100 """
109- return load_all (stream , DangerLoader )
101+ return load_all (stream , SafeLoader )
110102
111103def emit (events , stream = None , Dumper = Dumper ,
112104 canonical = None , indent = None , width = None ,
@@ -201,31 +193,29 @@ def dump_all(documents, stream=None, Dumper=Dumper,
201193 dumper .dispose ()
202194 if getvalue :
203195 return getvalue ()
204- safe_dump_all = dump_all
205196
206- def danger_dump_all ( documents , stream = None , ** kwds ):
197+ def dump ( data , stream = None , Dumper = Dumper , ** kwds ):
207198 """
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.
210200 If stream is None, return the produced string instead.
211201 """
212- return dump_all (documents , stream , Dumper = DangerDumper , ** kwds )
202+ return dump_all ([ data ] , stream , Dumper = Dumper , ** kwds )
213203
214- def dump ( data , stream = None , Dumper = Dumper , ** kwds ):
204+ def safe_dump_all ( documents , stream = None , ** kwds ):
215205 """
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.
217208 If stream is None, return the produced string instead.
218209 """
219- return dump_all ([data ], stream , Dumper = Dumper , ** kwds )
220- safe_dump = dump
210+ return dump_all (documents , stream , Dumper = SafeDumper , ** kwds )
221211
222- def danger_dump (data , stream = None , ** kwds ):
212+ def safe_dump (data , stream = None , ** kwds ):
223213 """
224214 Serialize a Python object into a YAML stream.
225215 Produce only basic YAML tags.
226216 If stream is None, return the produced string instead.
227217 """
228- return dump_all ([data ], stream , Dumper = DangerDumper , ** kwds )
218+ return dump_all ([data ], stream , Dumper = SafeDumper , ** kwds )
229219
230220def add_implicit_resolver (tag , regexp , first = None ,
231221 Loader = Loader , Dumper = Dumper ):
@@ -322,3 +312,4 @@ def to_yaml(cls, dumper, data):
322312 return dumper .represent_yaml_object (cls .yaml_tag , data , cls ,
323313 flow_style = cls .yaml_flow_style )
324314 to_yaml = classmethod (to_yaml )
315+
0 commit comments