From c183fa3c83c2590b663056b4b77d46d81975f30d Mon Sep 17 00:00:00 2001 From: Alexander Loechel Date: Thu, 4 May 2017 10:18:09 +0200 Subject: [PATCH 1/2] add PendingDeprecationWarnings --- src/RestrictedPython/MutatingWalker.py | 10 +++++++ src/RestrictedPython/RCompile.py | 33 ++++++++++++++++++++++ src/RestrictedPython/RestrictionMutator.py | 10 +++++++ src/RestrictedPython/SelectCompiler.py | 9 ++++++ src/RestrictedPython/tests/verify.py | 8 ++++++ 5 files changed, 70 insertions(+) diff --git a/src/RestrictedPython/MutatingWalker.py b/src/RestrictedPython/MutatingWalker.py index 0dbf75b..4aaa1d1 100644 --- a/src/RestrictedPython/MutatingWalker.py +++ b/src/RestrictedPython/MutatingWalker.py @@ -13,6 +13,16 @@ from compiler import ast +import warnings + + +warnings.warn( + "This Module (RestrictedPython.MutatingWalker) is deprecated" + "and will be gone soon.", + category=PendingDeprecationWarning, + stacklevel=1 +) + ListType = type([]) TupleType = type(()) diff --git a/src/RestrictedPython/RCompile.py b/src/RestrictedPython/RCompile.py index 017e96e..2f234c4 100644 --- a/src/RestrictedPython/RCompile.py +++ b/src/RestrictedPython/RCompile.py @@ -30,6 +30,15 @@ from RestrictionMutator import RestrictionMutator import MutatingWalker +import warnings + + +warnings.warn( + "This Module (RestrictedPython.RCompile) is deprecated" + "and will be gone soon.", + category=PendingDeprecationWarning, + stacklevel=1 +) def niceParse(source, filename, mode): @@ -101,24 +110,48 @@ def compile_restricted_function(p, body, name, filename, globalize=None): treated as globals (code is generated as if each name in the list appeared in a global statement at the top of the function). """ + warnings.warn( + "RestrictedPython.RCompile.compile_restricted_function is deprecated" + "use RestrictedPython.compile_restricted_function instead.", + category=PendingDeprecationWarning, + stacklevel=1 + ) gen = RFunction(p, body, name, filename, globalize) return compileAndTuplize(gen) def compile_restricted_exec(source, filename=''): """Compiles a restricted code suite.""" + warnings.warn( + "RestrictedPython.RCompile.compile_restricted_exec is deprecated" + "use RestrictedPython.compile_restricted_exec instead.", + category=PendingDeprecationWarning, + stacklevel=1 + ) gen = RModule(source, filename) return compileAndTuplize(gen) def compile_restricted_eval(source, filename=''): """Compiles a restricted expression.""" + warnings.warn( + "RestrictedPython.RCompile.compile_restricted_eval is deprecated" + "use RestrictedPython.compile_restricted_eval instead.", + category=PendingDeprecationWarning, + stacklevel=1 + ) gen = RExpression(source, filename) return compileAndTuplize(gen) def compile_restricted(source, filename, mode): """Replacement for the builtin compile() function.""" + warnings.warn( + "RestrictedPython.RCompile.compile_restricted is deprecated" + "use RestrictedPython.compile_restricted instead.", + category=PendingDeprecationWarning, + stacklevel=1 + ) if mode == "single": gen = RInteractive(source, filename) elif mode == "exec": diff --git a/src/RestrictedPython/RestrictionMutator.py b/src/RestrictedPython/RestrictionMutator.py index 3c22f90..743a0cb 100644 --- a/src/RestrictedPython/RestrictionMutator.py +++ b/src/RestrictedPython/RestrictionMutator.py @@ -23,6 +23,16 @@ from compiler.consts import OP_DELETE from compiler.transformer import parse +import warnings + + +warnings.warn( + "This Module (RestrictedPython.RestrictionMutator) is deprecated" + "and will be gone soon.", + category=PendingDeprecationWarning, + stacklevel=1 +) + # These utility functions allow us to generate AST subtrees without # line number attributes. These trees can then be inserted into other diff --git a/src/RestrictedPython/SelectCompiler.py b/src/RestrictedPython/SelectCompiler.py index ad0d80d..debda17 100644 --- a/src/RestrictedPython/SelectCompiler.py +++ b/src/RestrictedPython/SelectCompiler.py @@ -25,3 +25,12 @@ # Use the compiler from the standard library. import compiler +import warnings + + +warnings.warn( + "This Module (RestrictedPython.SelectCompiler) is deprecated" + "and will be gone soon.", + category=PendingDeprecationWarning, + stacklevel=1 +) diff --git a/src/RestrictedPython/tests/verify.py b/src/RestrictedPython/tests/verify.py index 8fd086f..c3122b4 100644 --- a/src/RestrictedPython/tests/verify.py +++ b/src/RestrictedPython/tests/verify.py @@ -23,6 +23,7 @@ import dis import types +import warnings def verify(code): @@ -31,6 +32,13 @@ def verify(code): In particular, traverse into contained code objects in the co_consts table. """ + warnings.warn( + "RestrictedPython.test.verify is deprecated and will be gone soon." + "verify() tests on byte code level, which did not make sense" + "with new implementation which is Python Implementation independend.", + category=PendingDeprecationWarning, + stacklevel=1 + ) verifycode(code) for ob in code.co_consts: if isinstance(ob, types.CodeType): From 4942f24a32759c5bf5b762d64085018ce6b7fca9 Mon Sep 17 00:00:00 2001 From: Alexander Loechel Date: Thu, 4 May 2017 10:34:14 +0200 Subject: [PATCH 2/2] Public API --> RestrictionCapableEval added after resolved problem of circular imports --- src/RestrictedPython/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/RestrictedPython/__init__.py b/src/RestrictedPython/__init__.py index af8c84b..bf087cb 100644 --- a/src/RestrictedPython/__init__.py +++ b/src/RestrictedPython/__init__.py @@ -17,7 +17,7 @@ # as this file should be logically grouped imports -# Old API --> Old Import Locations +# Old API --> Old Import Locations (Deprecated) # from RestrictedPython.RCompile import compile_restricted # from RestrictedPython.RCompile import compile_restricted_eval # from RestrictedPython.RCompile import compile_restricted_exec @@ -43,5 +43,5 @@ # Policy from RestrictedPython.transformer import RestrictingNodeTransformer # isort:skip - -# from RestrictedPython.Eval import RestrictionCapableEval +# +from RestrictedPython.Eval import RestrictionCapableEval