| | 1241 | {{{ |
| | 1242 | #!python |
| | 1243 | dump(data, stream=None, Dumper=Dumper, |
| | 1244 | default_style=None, |
| | 1245 | default_flow_style=None, |
| | 1246 | encoding='utf-8', |
| | 1247 | explicit_start=None, |
| | 1248 | explicit_end=None, |
| | 1249 | version=None, |
| | 1250 | tags=None, |
| | 1251 | canonical=None, |
| | 1252 | indent=None, |
| | 1253 | width=None, |
| | 1254 | allow_unicode=None, |
| | 1255 | line_break=None) |
| | 1256 | dump_all(data, stream=None, Dumper=Dumper, ...) |
| | 1257 | |
| | 1258 | safe_dump(data, stream=None, ...) |
| | 1259 | safe_dump_all(data, stream=None, ...) |
| | 1260 | |
| | 1261 | Dumper.represent(data) |
| | 1262 | |
| | 1263 | def representer(dumper, data): |
| | 1264 | # ... |
| | 1265 | return node |
| | 1266 | |
| | 1267 | def multi_representer(dumper, data): |
| | 1268 | # ... |
| | 1269 | return node |
| | 1270 | |
| | 1271 | add_representer(data_type, representer, Dumper=Dumper) |
| | 1272 | add_multi_representer(base_data_type, multi_representer, Dumper=Dumper) |
| | 1273 | |
| | 1274 | Dumper.add_representer(data_type, representer) # Dumper.add_representer is a class method. |
| | 1275 | Dumper.add_multi_representer(base_data_type, multi_representer) # Dumper.add_multi_representer is a class method. |
| | 1276 | |
| | 1277 | Dumper.represent_scalar(tag, value, style=None) |
| | 1278 | Dumper.represent_sequence(tag, value, flow_style=None) |
| | 1279 | Dumper.represent_mapping(tag, value, flow_style=None) |
| | 1280 | }}} |
| | 1281 | |
| | 1282 | '''`dump(data, stream=None)`''' serializes the given Python object into the `stream`. |
| | 1283 | If `stream` is `None`, it returns the produced stream. |
| | 1284 | |
| | 1285 | '''`dump_all(data, stream=None)`''' serializes the given sequence of Python objects |
| | 1286 | into the given `stream`. If `stream` is `None`, it returns the produced stream. |
| | 1287 | Each object is represented as a YAML document. |
| | 1288 | |
| | 1289 | '''`safe_dump(data, stream=None)`''' serializes the given Python object into the `stream`. |
| | 1290 | If `stream` is `None`, it returns the produced stream. `safe_dump` produces only standard YAML |
| | 1291 | tags and cannot represent an arbitrary Python object. |
| | 1292 | |
| | 1293 | '''`safe_dump_all(data, stream=None)`''' serializes the given sequence of Python objects |
| | 1294 | into the given `stream`. If `stream` is `None`, it returns the produced stream. |
| | 1295 | Each object is represented as a YAML document. `safe_dump_all` produces only standard YAML |
| | 1296 | tags and cannot represent an arbitrary Python object. |
| | 1297 | |
| | 1298 | '''`Dumper.represent(data)`''' serializes the given Python object to the output YAML stream. |
| | 1299 | |
| | 1300 | '''`add_representer(data_type, representer)`''' and '''`Dumper.add_representer(data_type, representer)`''' |
| | 1301 | allow to specify a `representer` for Python objects of the given `data_type`. A representer is a function |
| | 1302 | that converts a native Python object to a node of a YAML representation graph. A representer accepts |
| | 1303 | an instance of `Dumper` and an object and returns a node. |
| | 1304 | |
| | 1305 | '''`add_multi_representer(base_data_type, multi_representer)`''' and '''`Dumper.add_multi_representer(base_data_type, multi_representer)`''' |
| | 1306 | allow to specify a `multi_representer` for Python objects of the given `base_data_type` or any of its subclasses. |
| | 1307 | A multi-representer is a function that converts a native Python object to a node of a YAML representation graph. |
| | 1308 | A multi-representer accepts an instance of `Dumper` and an object and returns a node. |
| | 1309 | |
| | 1310 | '''`Dumper.represent_scalar(tag, value, style=None)`''' returns a scalar node with the given `tag`, `value`, and `style`. |
| | 1311 | This function is intended to be used in representers. |
| | 1312 | |
| | 1313 | '''`Dumper.represent_sequence(tag, sequence, flow_style=None)`''' return a sequence node with the given `tag` |
| | 1314 | and subnodes generated from the items of the given `sequence`. |
| | 1315 | |
| | 1316 | '''`Dumper.represent_mapping(tag, mapping, flow_style=None)`''' return a mapping node with the given `tag` |
| | 1317 | and subnodes generated from the keys and values of the given `mapping`. |
| | 1318 | |