Skip to content

Commit

Permalink
Merge branch 'Python3_update' into ast_doc_warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
loechel committed Feb 3, 2017
2 parents 1967210 + b8a55a6 commit 117c249
Show file tree
Hide file tree
Showing 8 changed files with 210 additions and 129 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ branch = True
source = RestrictedPython

[report]
precision = 2
precision = 3
5 changes: 0 additions & 5 deletions src/RestrictedPython/tests/lambda.py

This file was deleted.

16 changes: 0 additions & 16 deletions src/RestrictedPython/tests/security_in_syntax27.py

This file was deleted.

3 changes: 1 addition & 2 deletions src/RestrictedPython/tests/testCompile.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
#
##############################################################################

# Ported
# Need to be ported
from RestrictedPython.RCompile import _niceParse

import compiler.ast
import unittest


# Ported --> test_niceParse.py
class CompileTests(unittest.TestCase):

def testUnicodeSource(self):
Expand Down
31 changes: 0 additions & 31 deletions src/RestrictedPython/tests/testRestrictions.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,33 +295,6 @@ def test_Denied(self):
else:
self.fail('%s() did not trip security' % k)

def test_SyntaxSecurity(self):
if sys.version_info >= (2, 7):
self._test_SyntaxSecurity('security_in_syntax27.py')

def _test_SyntaxSecurity(self, mod_name):
# Ensures that each of the functions in security_in_syntax.py
# throws a SyntaxError when using compile_restricted.
fn = os.path.join(_HERE, mod_name)
f = open(fn, 'r')
source = f.read()
f.close()
# Unrestricted compile.
code = compile(source, fn, 'exec')
m = {'__builtins__': {'__import__': minimal_import}}
exec(code, m)
for k, v in m.items():
if hasattr(v, 'func_code'):
filename, source = find_source(fn, v.func_code)
# Now compile it with restrictions
try:
code = compile_restricted(source, filename, 'exec')
except SyntaxError:
# Passed the test.
pass
else:
self.fail('%s should not have compiled' % k)

def test_OrderOfOperations(self):
res = self.execFunc('order_of_operations')
self.assertEqual(res, 0)
Expand Down Expand Up @@ -478,10 +451,6 @@ def test_setattr(obj):
["set", "set", "get", "state", "get", "state"])
self.assertEqual(setattr_calls, ["MyClass", "MyClass"])

def test_Lambda(self):
co = self._compile_file("lambda.py")
exec(co, {}, {})

def test_Empty(self):
rf = RFunction("", "", "issue945", "empty.py", {})
rf.parse()
Expand Down
90 changes: 28 additions & 62 deletions src/RestrictedPython/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,70 +758,48 @@ def visit_Or(self, node):
self.not_allowed(node)

def visit_Compare(self, node):
"""
"""
"""Allow comparison expressions without restrictions."""
return self.node_contents_visit(node)

def visit_Eq(self, node):
"""
"""
self.not_allowed(node)
"""Allow == expressions."""
return self.node_contents_visit(node)

def visit_NotEq(self, node):
"""
"""
self.not_allowed(node)
"""Allow != expressions."""
return self.node_contents_visit(node)

def visit_Lt(self, node):
"""
"""
self.not_allowed(node)
"""Allow < expressions."""
return self.node_contents_visit(node)

def visit_LtE(self, node):
"""
"""
self.not_allowed(node)
"""Allow <= expressions."""
return self.node_contents_visit(node)

def visit_Gt(self, node):
"""
"""
"""Allow > expressions."""
return self.node_contents_visit(node)

def visit_GtE(self, node):
"""
"""
self.not_allowed(node)
"""Allow >= expressions."""
return self.node_contents_visit(node)

def visit_Is(self, node):
"""
"""
"""Allow `is` expressions."""
return self.node_contents_visit(node)

def visit_IsNot(self, node):
"""
"""
self.not_allowed(node)
"""Allow `is not` expressions."""
return self.node_contents_visit(node)

def visit_In(self, node):
"""
"""
self.not_allowed(node)
"""Allow `in` expressions."""
return self.node_contents_visit(node)

def visit_NotIn(self, node):
"""
"""
self.not_allowed(node)
"""Allow `not in` expressions."""
return self.node_contents_visit(node)

def visit_Call(self, node):
"""Checks calls with '*args' and '**kwargs'.
Expand Down Expand Up @@ -1158,10 +1136,8 @@ def visit_Raise(self, node):
return self.node_contents_visit(node)

def visit_Assert(self, node):
"""
"""
self.not_allowed(node)
"""Allow assert statements without restrictions."""
return self.node_contents_visit(node)

def visit_Delete(self, node):
"""
Expand Down Expand Up @@ -1201,34 +1177,24 @@ def visit_Exec(self, node):
# Control flow

def visit_If(self, node):
"""
"""
"""Allow `if` statements without restrictions."""
return self.node_contents_visit(node)

def visit_For(self, node):
"""
"""
"""Allow `for` statements with some restrictions."""
return self.guard_iter(node)

def visit_While(self, node):
"""
"""
self.not_allowed(node)
"""Allow `while` statements."""
return self.node_contents_visit(node)

def visit_Break(self, node):
"""
"""
"""Allow `break` statements without restrictions."""
return self.node_contents_visit(node)

def visit_Continue(self, node):
"""
"""
self.not_allowed(node)
"""Allow `continue` statements without restrictions."""
return self.node_contents_visit(node)

def visit_Try(self, node):
"""Allow Try without restrictions.
Expand Down
Loading

0 comments on commit 117c249

Please sign in to comment.