| 959 | | SafeLoader(stream) |
| 960 | | Loader(stream) |
| 961 | | }}} |
| 962 | | |
| 963 | | '''`BaseLoader`''', '''`SafeLoader`''', and '''`Loader`''' provide the PyYAML ''Loader'' interfaces. |
| 964 | | '''`Loader`''' is the most common of them and should be used in most cases. '''`BaseLoader`''' does not |
| 965 | | resolve or support any tags and construct only basic Python objects: lists, dictionaries and Unicode strings. |
| 966 | | '''`SafeLoader`''' supports only standard YAML tags and thus it does not construct class instances and |
| 967 | | probably safe to use with documents received from an untrusted source. |
| 968 | | |
| 969 | | '''`stream`''' is an input YAML stream. It can be a string, a Unicode string, an open file, an open Unicode file. |
| | 961 | }}} |
| | 962 | |
| | 963 | '''`BaseLoader`''', '''`SafeLoader`''', and '''`Loader`''' provide the following interfaces: |
| | 964 | ''Scanner'', ''Parser'', ''Composer'', ''Constructor'', ''Resolver''. |
| | 965 | |
| | 966 | '''`Loader(stream)`''' is the most common of the above classes and should be used in most cases. |
| | 967 | `stream` is an input YAML stream. It can be a string, a Unicode string, an open file, an open Unicode file. |
| | 968 | |
| | 969 | '''`Loader`''' supports all predefined tags and may construct an arbitrary Python object. Therefore it is not safe to use |
| | 970 | `Loader` to load a document received from an untrusted source. By default, the functions `scan`, `parse`, |
| | 971 | `compose`, `construct`, and others use `Loader`. |
| | 972 | |
| | 973 | '''`SafeLoader(stream)`''' supports only standard YAML tags and thus it does not construct class instances and |
| | 974 | probably safe to use with documents received from an untrusted source. The functions `safe_load` and |
| | 975 | `safe_load_all` use `SafeLoader` to parse a stream. |
| | 976 | |
| | 977 | '''`BaseLoader(stream)`''' does not resolve or support any tags and construct only basic Python objects: |
| | 978 | lists, dictionaries and Unicode strings. |
| | 979 | |
| | 1029 | |
| | 1030 | {{{ |
| | 1031 | #!python |
| | 1032 | compose(stream, Loader=Loader) |
| | 1033 | compose_all(stream, Loader=Loader) |
| | 1034 | |
| | 1035 | Loader.check_node() |
| | 1036 | Loader.get_node() |
| | 1037 | }}} |
| | 1038 | |
| | 1039 | '''`compose(stream)`''' parses the given `stream` and returns the root of the representation graph |
| | 1040 | for the first document in the stream. If there are no documents in the stream, it returns `None`. |
| | 1041 | |
| | 1042 | '''`compose_all(stream)`''' parses the given `stream` and returns a sequence of representation graphs |
| | 1043 | corresponding to the documents in the stream. |
| | 1044 | |
| | 1045 | '''`Loader.check_node()`''' returns `True` is there are more documents available in the stream. Otherwise |
| | 1046 | it returns `False`. |
| | 1047 | |
| | 1048 | '''`Loader.get_node()`''' construct the representation graph of the next document in the stream and |
| | 1049 | returns its root node. |