[Checkins] SVN: RestrictedPython/trunk/ merge the davisagli-python27 branch

David Glick davidglick at onenw.org
Fri Jul 9 12:09:32 EDT 2010


Log message for revision 114379:
  merge the davisagli-python27 branch

Changed:
  U   RestrictedPython/trunk/CHANGES.txt
  U   RestrictedPython/trunk/src/RestrictedPython/Guards.py
  U   RestrictedPython/trunk/src/RestrictedPython/README.txt
  U   RestrictedPython/trunk/src/RestrictedPython/RestrictionMutator.py
  A   RestrictedPython/trunk/src/RestrictedPython/tests/before_and_after27.py
  U   RestrictedPython/trunk/src/RestrictedPython/tests/security_in_syntax.py
  U   RestrictedPython/trunk/src/RestrictedPython/tests/security_in_syntax26.py
  A   RestrictedPython/trunk/src/RestrictedPython/tests/security_in_syntax27.py
  U   RestrictedPython/trunk/src/RestrictedPython/tests/testRestrictions.py

-=-
Modified: RestrictedPython/trunk/CHANGES.txt
===================================================================
--- RestrictedPython/trunk/CHANGES.txt	2010-07-09 15:59:45 UTC (rev 114378)
+++ RestrictedPython/trunk/CHANGES.txt	2010-07-09 16:09:31 UTC (rev 114379)
@@ -4,7 +4,15 @@
 3.6.0 (unreleased)
 ------------------
 
+- Added name check for names assigned during imports using the
+  "from x import y" format.
 
+- Added test for name check when assigning an alias using multiple-context with
+  statements in Python 2.7.
+
+- Added tests for protection of the iterators for dict and set comprehensions
+  in Python 2.7.
+
 3.6.0a1 (2010-06-05)
 --------------------
 

Modified: RestrictedPython/trunk/src/RestrictedPython/Guards.py
===================================================================
--- RestrictedPython/trunk/src/RestrictedPython/Guards.py	2010-07-09 15:59:45 UTC (rev 114378)
+++ RestrictedPython/trunk/src/RestrictedPython/Guards.py	2010-07-09 16:09:31 UTC (rev 114379)
@@ -71,10 +71,13 @@
 # one should care.
 
 # buffer
+# bytes
+# bytearray
 # classmethod
 # coerce
 # eval
 # intern
+# memoryview
 # object
 # property
 # reload

Modified: RestrictedPython/trunk/src/RestrictedPython/README.txt
===================================================================
--- RestrictedPython/trunk/src/RestrictedPython/README.txt	2010-07-09 15:59:45 UTC (rev 114378)
+++ RestrictedPython/trunk/src/RestrictedPython/README.txt	2010-07-09 16:09:31 UTC (rev 114379)
@@ -24,6 +24,12 @@
   >>> hello_world()
   'Hello World!'
 
+Compatibility
+=============
+
+This release of RestrictedPython is compatible with Python 2.3, 2.4, 2.5, 2.6,
+and 2.7.
+
 Implementing a policy
 =====================
 

Modified: RestrictedPython/trunk/src/RestrictedPython/RestrictionMutator.py
===================================================================
--- RestrictedPython/trunk/src/RestrictedPython/RestrictionMutator.py	2010-07-09 15:59:45 UTC (rev 114378)
+++ RestrictedPython/trunk/src/RestrictedPython/RestrictionMutator.py	2010-07-09 16:09:31 UTC (rev 114379)
@@ -400,3 +400,5 @@
             if asname:
                 self.checkName(node, asname)
         return node
+
+    visitFrom = visitImport

Copied: RestrictedPython/trunk/src/RestrictedPython/tests/before_and_after27.py (from rev 114378, RestrictedPython/branches/davisagli-python27/src/RestrictedPython/tests/before_and_after27.py)
===================================================================
--- RestrictedPython/trunk/src/RestrictedPython/tests/before_and_after27.py	                        (rev 0)
+++ RestrictedPython/trunk/src/RestrictedPython/tests/before_and_after27.py	2010-07-09 16:09:31 UTC (rev 114379)
@@ -0,0 +1,45 @@
+##############################################################################
+#
+# Copyright (c) 2010 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Restricted Python transformation examples
+
+This module contains pairs of functions. Each pair has a before and an
+after function.  The after function shows the source code equivalent
+of the before function after it has been modified by the restricted
+compiler.
+
+These examples are actually used in the testRestrictions.py
+checkBeforeAndAfter() unit tests, which verifies that the restricted compiler
+actually produces the same output as would be output by the normal compiler
+for the after function.
+"""
+
+# dictionary and set comprehensions
+
+def simple_dict_comprehension_before():
+    x = {y: y for y in whatever if y}
+
+def simple_dict_comprehension_after():
+    x = {y: y for y in _getiter_(whatever) if y}
+
+def dict_comprehension_attrs_before():
+    x = {y: y.q for y in whatever.z if y.q}
+
+def dict_comprehension_attrs_after():
+    x = {y: _getattr_(y, 'q') for y in _getiter_(_getattr_(whatever, 'z')) if _getattr_(y, 'q')}
+
+def simple_set_comprehension_before():
+    x = {y for y in whatever if y}
+
+def simple_set_comprehension_after():
+    x = {y for y in _getiter_(whatever) if y}

Modified: RestrictedPython/trunk/src/RestrictedPython/tests/security_in_syntax.py
===================================================================
--- RestrictedPython/trunk/src/RestrictedPython/tests/security_in_syntax.py	2010-07-09 15:59:45 UTC (rev 114378)
+++ RestrictedPython/trunk/src/RestrictedPython/tests/security_in_syntax.py	2010-07-09 16:09:31 UTC (rev 114379)
@@ -41,6 +41,9 @@
 def import_as_bad_name():
     import os as _leading_underscore
 
+def from_import_as_bad_name():
+    from x import y as _leading_underscore
+
 def except_using_bad_name():
     try:
         foo

Modified: RestrictedPython/trunk/src/RestrictedPython/tests/security_in_syntax26.py
===================================================================
--- RestrictedPython/trunk/src/RestrictedPython/tests/security_in_syntax26.py	2010-07-09 15:59:45 UTC (rev 114378)
+++ RestrictedPython/trunk/src/RestrictedPython/tests/security_in_syntax26.py	2010-07-09 16:09:31 UTC (rev 114379)
@@ -5,3 +5,12 @@
 def with_as_bad_name():
     with x as _leading_underscore:
         pass
+
+def relative_import_as_bad_name():
+    from .x import y as _leading_underscore
+
+def except_as_bad_name():
+    try:
+        1/0
+    except Exception as _leading_underscore:
+        pass

Copied: RestrictedPython/trunk/src/RestrictedPython/tests/security_in_syntax27.py (from rev 114378, RestrictedPython/branches/davisagli-python27/src/RestrictedPython/tests/security_in_syntax27.py)
===================================================================
--- RestrictedPython/trunk/src/RestrictedPython/tests/security_in_syntax27.py	                        (rev 0)
+++ RestrictedPython/trunk/src/RestrictedPython/tests/security_in_syntax27.py	2010-07-09 16:09:31 UTC (rev 114379)
@@ -0,0 +1,13 @@
+# These are all supposed to raise a SyntaxError when using
+# compile_restricted() but not when using compile().
+# Each function in this module is compiled using compile_restricted().
+
+def dict_comp_bad_name():
+    {y: y for _restricted_name in x}
+
+def set_comp_bad_name():
+    {y for _restricted_name in x}
+
+def compound_with_bad_name():
+    with a as b, c as _restricted_name:
+        pass

Modified: RestrictedPython/trunk/src/RestrictedPython/tests/testRestrictions.py
===================================================================
--- RestrictedPython/trunk/src/RestrictedPython/tests/testRestrictions.py	2010-07-09 15:59:45 UTC (rev 114378)
+++ RestrictedPython/trunk/src/RestrictedPython/tests/testRestrictions.py	2010-07-09 16:09:31 UTC (rev 114379)
@@ -277,6 +277,8 @@
         self._checkSyntaxSecurity('security_in_syntax.py')
         if sys.version_info >= (2, 6):
             self._checkSyntaxSecurity('security_in_syntax26.py')
+        if sys.version_info >= (2, 7):
+            self._checkSyntaxSecurity('security_in_syntax27.py')
 
     def _checkSyntaxSecurity(self, mod_name):
         # Ensures that each of the functions in security_in_syntax.py
@@ -403,6 +405,11 @@
             from RestrictedPython.tests import before_and_after26
             self._checkBeforeAndAfter(before_and_after26)
 
+    if sys.version_info[:2] >= (2, 7):
+        def checkBeforeAndAfter27(self):
+            from RestrictedPython.tests import before_and_after27
+            self._checkBeforeAndAfter(before_and_after27)
+
     def _compile_file(self, name):
         path = os.path.join(_HERE, name)
         f = open(path, "r")



More information about the checkins mailing list