From 39d3f0eb58e55c84592b07771a5f48503525d6cc Mon Sep 17 00:00:00 2001 From: Anthon van der Neut Date: Sun, 20 Nov 2016 19:29:11 +0100 Subject: fix #6: non-safe load() now issues warning added method to add before/after comments on specific keys --- error.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'error.py') diff --git a/error.py b/error.py index e93c20e..20c7979 100644 --- a/error.py +++ b/error.py @@ -2,9 +2,12 @@ from __future__ import absolute_import +import warnings + from ruamel.yaml.compat import utf8 -__all__ = ['Mark', 'YAMLError', 'MarkedYAMLError', 'ReusedAnchorWarning'] +__all__ = ['Mark', 'YAMLError', 'MarkedYAMLError', 'ReusedAnchorWarning', + 'UnsafeLoaderWarning'] class Mark(object): @@ -84,3 +87,18 @@ class MarkedYAMLError(YAMLError): class ReusedAnchorWarning(Warning): pass + + +class UnsafeLoaderWarning(Warning): + text = """ +The default 'Loader' for 'load(stream)' without further arguments can be unsafe. +Use 'load(stream, Loader=ruamel.yaml.Loader)' explicitly if that is OK. +Alternatively include the following in your code: + + import warnings + warnings.simplefilter('ignore', ruamel.yaml.error.UnsafeLoaderWarning) + +In most other cases you should consider using 'safe_load(stream)'""" + pass + +warnings.simplefilter('once', UnsafeLoaderWarning) -- cgit v1.2.1