diff options
author | Anthon van der Neut <anthon@mnt.org> | 2016-11-20 19:29:11 +0100 |
---|---|---|
committer | Anthon van der Neut <anthon@mnt.org> | 2016-11-20 19:29:11 +0100 |
commit | 39d3f0eb58e55c84592b07771a5f48503525d6cc (patch) | |
tree | 73e90db7810c9e563729b5d1a555ccf83be1f772 /main.py | |
parent | 3954b8bf203540dc69fa40c649c0db049d4ad938 (diff) | |
download | ruamel.yaml-39d3f0eb58e55c84592b07771a5f48503525d6cc.tar.gz |
fix #6: non-safe load() now issues warning0.13.0
added method to add before/after comments on specific keys
Diffstat (limited to 'main.py')
-rw-r--r-- | main.py | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -70,12 +70,17 @@ def compose_all(stream, Loader=Loader): loader.dispose() -def load(stream, Loader=Loader, version=None, preserve_quotes=None): +def load(stream, Loader=None, version=None, preserve_quotes=None): # type: (StreamType, Any, VersionType, Any) -> Any """ Parse the first YAML document in a stream and produce the corresponding Python object. """ + if Loader is None: + from ruamel.yaml.loader import Loader as UnsafeLoader + import warnings + warnings.warn(UnsafeLoaderWarning.text, UnsafeLoaderWarning, stacklevel=2) + Loader = UnsafeLoader loader = Loader(stream, version, preserve_quotes=preserve_quotes) try: return loader.get_single_data() @@ -83,11 +88,16 @@ def load(stream, Loader=Loader, version=None, preserve_quotes=None): loader.dispose() -def load_all(stream, Loader=Loader, version=None, preserve_quotes=None): +def load_all(stream, Loader=None, version=None, preserve_quotes=None): """ Parse all YAML documents in a stream and produce corresponding Python objects. """ + if Loader is None: + from ruamel.yaml.loader import Loader as UnsafeLoader + import warnings + warnings.warn(UnsafeLoaderWarning.text, UnsafeLoaderWarning, stacklevel=2) + Loader = UnsafeLoader loader = Loader(stream, version, preserve_quotes=preserve_quotes) try: while loader.check_data(): |