[Zope-Checkins] SVN: Zope/trunk/ Merge fix for issue #945.
Tres Seaver
tseaver at zope.com
Fri Nov 26 13:27:43 EST 2004
Log message for revision 28525:
Merge fix for issue #945.
Changed:
U Zope/trunk/doc/CHANGES.txt
U Zope/trunk/lib/python/RestrictedPython/RCompile.py
U Zope/trunk/lib/python/RestrictedPython/tests/testRestrictions.py
-=-
Modified: Zope/trunk/doc/CHANGES.txt
===================================================================
--- Zope/trunk/doc/CHANGES.txt 2004-11-26 18:20:31 UTC (rev 28524)
+++ Zope/trunk/doc/CHANGES.txt 2004-11-26 18:27:43 UTC (rev 28525)
@@ -46,6 +46,9 @@
Bugs fixed
+ - Collector #945: Allow adding empty PythonScript instances
+ programmatically.
+
- Updated doc/UNITTEST.txt and lib/python/Testing/README.txt to
reflect progress made since UNITTEST.txt was originally written.
Modified: Zope/trunk/lib/python/RestrictedPython/RCompile.py
===================================================================
--- Zope/trunk/lib/python/RestrictedPython/RCompile.py 2004-11-26 18:20:31 UTC (rev 28524)
+++ Zope/trunk/lib/python/RestrictedPython/RCompile.py 2004-11-26 18:27:43 UTC (rev 28525)
@@ -220,12 +220,13 @@
# Stitch the body code into the function.
f.code.nodes = body_code.node.nodes
f.name = self.name
- # Look for a docstring.
- stmt1 = f.code.nodes[0]
- if (isinstance(stmt1, ast.Discard) and
- isinstance(stmt1.expr, ast.Const) and
- isinstance(stmt1.expr.value, str)):
- f.doc = stmt1.expr.value
+ # Look for a docstring, if there are any nodes at all
+ if len(f.code.nodes) > 0:
+ stmt1 = f.code.nodes[0]
+ if (isinstance(stmt1, ast.Discard) and
+ isinstance(stmt1.expr, ast.Const) and
+ isinstance(stmt1.expr.value, str)):
+ f.doc = stmt1.expr.value
# The caller may specify that certain variables are globals
# so that they can be referenced before a local assignment.
# The only known example is the variables context, container,
Modified: Zope/trunk/lib/python/RestrictedPython/tests/testRestrictions.py
===================================================================
--- Zope/trunk/lib/python/RestrictedPython/tests/testRestrictions.py 2004-11-26 18:20:31 UTC (rev 28524)
+++ Zope/trunk/lib/python/RestrictedPython/tests/testRestrictions.py 2004-11-26 18:27:43 UTC (rev 28525)
@@ -13,7 +13,7 @@
from RestrictedPython import compile_restricted, PrintCollector
from RestrictedPython.Eval import RestrictionCapableEval
from RestrictedPython.tests import before_and_after, restricted_module, verify
-from RestrictedPython.RCompile import RModule
+from RestrictedPython.RCompile import RModule, RFunction
try:
__file__
@@ -437,6 +437,12 @@
co = self._compile_file("lambda.py")
exec co in {}, {}
+ def checkEmpty(self):
+ rf = RFunction("", "", "issue945", "empty.py", {})
+ rf.parse()
+ rf2 = RFunction("", "# still empty\n\n# by", "issue945", "empty.py", {})
+ rf2.parse()
+
def checkSyntaxError(self):
err = ("def f(x, y):\n"
" if x, y < 2 + 1:\n"
More information about the Zope-Checkins
mailing list