diff --git a/Makefile b/Makefile index d72eaf0f..34a1d401 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -.PHONY: default build buildext force forceext install installext test testext dist clean +.PHONY: build dist PYTHON=/usr/bin/python3 TEST= @@ -42,3 +42,10 @@ windist: clean: ${PYTHON} setup.py --with-libyaml clean -a + rm -fr \ + dist/ \ + lib/PyYAML.egg-info/ \ + lib/yaml/__pycache__/ \ + tests/lib/__pycache__/ \ + yaml/_yaml.c \ + diff --git a/lib/yaml/__init__.py b/lib/yaml/__init__.py index 86d07b55..8c71105b 100644 --- a/lib/yaml/__init__.py +++ b/lib/yaml/__init__.py @@ -18,41 +18,12 @@ import io #------------------------------------------------------------------------------ -# Warnings control +# XXX "Warnings control" is now deprecated. Leaving in the API function to not +# break code that uses it. #------------------------------------------------------------------------------ - -# 'Global' warnings state: -_warnings_enabled = { - 'YAMLLoadWarning': True, -} - -# Get or set global warnings' state def warnings(settings=None): if settings is None: - return _warnings_enabled - - if type(settings) is dict: - for key in settings: - if key in _warnings_enabled: - _warnings_enabled[key] = settings[key] - -# Warn when load() is called without Loader=... -class YAMLLoadWarning(RuntimeWarning): - pass - -def load_warning(method): - if _warnings_enabled['YAMLLoadWarning'] is False: - return - - import warnings - - message = ( - "calling yaml.%s() without Loader=... is deprecated, as the " - "default Loader is unsafe. Please read " - "https://msg.pyyaml.org/load for full details." - ) % method - - warnings.warn(message, YAMLLoadWarning, stacklevel=3) + return {} #------------------------------------------------------------------------------ def scan(stream, Loader=Loader): @@ -100,30 +71,22 @@ def compose_all(stream, Loader=Loader): finally: loader.dispose() -def load(stream, Loader=None): +def load(stream, Loader): """ Parse the first YAML document in a stream and produce the corresponding Python object. """ - if Loader is None: - load_warning('load') - Loader = FullLoader - loader = Loader(stream) try: return loader.get_single_data() finally: loader.dispose() -def load_all(stream, Loader=None): +def load_all(stream, Loader): """ Parse all YAML documents in a stream and produce corresponding Python objects. """ - if Loader is None: - load_warning('load_all') - Loader = FullLoader - loader = Loader(stream) try: while loader.check_data(): diff --git a/tests/lib/test_appliance.py b/tests/lib/test_appliance.py index 592c12d2..0c5cda18 100644 --- a/tests/lib/test_appliance.py +++ b/tests/lib/test_appliance.py @@ -124,7 +124,7 @@ def run(collections, args=None): for function in test_functions: if include_functions and function.__name__ not in include_functions: continue - if function.unittest: + if function.unittest and function.unittest is not True: for base, exts in test_filenames: if include_filenames and base not in include_filenames: continue diff --git a/tests/lib/test_dump_load.py b/tests/lib/test_dump_load.py new file mode 100644 index 00000000..8f6e36f9 --- /dev/null +++ b/tests/lib/test_dump_load.py @@ -0,0 +1,24 @@ +import yaml + +def test_dump(verbose=False): + assert yaml.dump(['foo']) +test_dump.unittest = True + +def test_load_no_loader(verbose=False): + try: + yaml.load("- foo\n") + except TypeError: + return True + assert(False, "load() require Loader=...") + +test_load_no_loader.unittest = True + +def test_load_safeloader(verbose=False): + assert yaml.load("- foo\n", Loader=yaml.SafeLoader) +test_load_safeloader.unittest = True + +if __name__ == '__main__': + import sys, test_load + sys.modules['test_load'] = sys.modules['__main__'] + import test_appliance + test_appliance.run(globals()) diff --git a/tests/lib/test_yaml.py b/tests/lib/test_yaml.py index 7b3d8f9d..a5c10a38 100644 --- a/tests/lib/test_yaml.py +++ b/tests/lib/test_yaml.py @@ -1,4 +1,5 @@ +from test_dump_load import * from test_mark import * from test_reader import * from test_canonical import *