| | 1053 | |
| | 1054 | {{{ |
| | 1055 | #!python |
| | 1056 | load(stream, Loader=Loader) |
| | 1057 | load_all(stream, Loader=Loader) |
| | 1058 | |
| | 1059 | safe_load(stream) |
| | 1060 | safe_load_all(stream) |
| | 1061 | |
| | 1062 | Loader.check_data() |
| | 1063 | Loader.get_data() |
| | 1064 | |
| | 1065 | def constructor(loader, node): |
| | 1066 | # ... |
| | 1067 | return data |
| | 1068 | |
| | 1069 | def multi_constructor(loader, tag_suffix, node): |
| | 1070 | # ... |
| | 1071 | return data |
| | 1072 | |
| | 1073 | add_constructor(tag, constructor, Loader=Loader) |
| | 1074 | add_multi_constructor(tag_prefix, multi_constructor, Loader=Loader) |
| | 1075 | |
| | 1076 | Loader.add_constructor(tag, constructor) # Loader.add_constructor is a class method. |
| | 1077 | Loader.add_multi_constructor(tag_prefix, multi_constructor) # Loader.add_multi_constructor is a class method. |
| | 1078 | |
| | 1079 | Loader.construct_scalar(node) |
| | 1080 | Loader.construct_sequence(node) |
| | 1081 | Loader.construct_mapping(node) |
| | 1082 | }}} |
| | 1083 | |
| | 1084 | '''`construct(stream)`''' parses the given `stream` and returns a Python object constructed from |
| | 1085 | for the first document in the stream. If there are no documents in the stream, it returns `None`. |
| | 1086 | |
| | 1087 | '''`construct_all(stream)`''' parses the given `stream` and returns a sequence of Python objects |
| | 1088 | corresponding to the documents in the stream. |
| | 1089 | |
| | 1090 | '''`Loader.check_data()`''' returns `True` is there are more documents available in the stream. Otherwise |
| | 1091 | it returns `False`. |
| | 1092 | |
| | 1093 | '''`Loader.get_data()`''' constructs and returns a Python object corresponding to the next document |
| | 1094 | in the stream. |
| | 1095 | |
| | 1096 | '''`add_constructor(tag, constructor)`''' and '''`Loader.add_constructor(tag, constructor)`''' allow |
| | 1097 | to specify a `constructor` for the given `tag`. A constructor is a function that converts a node |
| | 1098 | of a YAML representation graph to a native Python object. A constructor accepts an instance of `Loader` |
| | 1099 | and a node and returns a Python object. |
| | 1100 | |
| | 1101 | '''`add_multi_constructor(tag_prefix, multi_constructor)`''' and '''`Loader.add_multi_constructor(tag_prefix, multi_constructor)`''' |
| | 1102 | allow to specify a `multi_constructor` for the given `tag_prefix`. A multi-constructor is a function that converts a node |
| | 1103 | of a YAML representation graph to a native Python object. A multi-constructor accepts an instance of `Loader`, |
| | 1104 | the suffix of the node tag, and a node and returns a Python object. |
| | 1105 | |
| | 1106 | '''`Loader.construct_scalar(node)`''' checks that the given `node` is a scalar and returns its value. |
| | 1107 | This function is intended to be used in constructors. |
| | 1108 | |
| | 1109 | '''`Loader.construct_sequence(node)`''' checks that the given `node` is a sequence and returns a list |
| | 1110 | of Python objects corresponding to the node items. This function is intended to be used in constructors. |
| | 1111 | |
| | 1112 | '''`Loader.construct_mapping(node)`''' checks that the given `node` is a mapping and returns a dictionary |
| | 1113 | of Python objects corresponding to the node keys and values. This function is intended to be used in constructors. |