Commit 8ea1fb82 authored by Tres Seaver's avatar Tres Seaver

Merge fix for issue #945.

parent af83b41e
...@@ -46,6 +46,9 @@ Zope Changes ...@@ -46,6 +46,9 @@ Zope Changes
Bugs fixed Bugs fixed
- Collector #945: Allow adding empty PythonScript instances
programmatically.
- Updated doc/UNITTEST.txt and lib/python/Testing/README.txt to - Updated doc/UNITTEST.txt and lib/python/Testing/README.txt to
reflect progress made since UNITTEST.txt was originally written. reflect progress made since UNITTEST.txt was originally written.
......
...@@ -220,12 +220,13 @@ class RFunction(RModule): ...@@ -220,12 +220,13 @@ class RFunction(RModule):
# Stitch the body code into the function. # Stitch the body code into the function.
f.code.nodes = body_code.node.nodes f.code.nodes = body_code.node.nodes
f.name = self.name f.name = self.name
# Look for a docstring. # Look for a docstring, if there are any nodes at all
stmt1 = f.code.nodes[0] if len(f.code.nodes) > 0:
if (isinstance(stmt1, ast.Discard) and stmt1 = f.code.nodes[0]
isinstance(stmt1.expr, ast.Const) and if (isinstance(stmt1, ast.Discard) and
isinstance(stmt1.expr.value, str)): isinstance(stmt1.expr, ast.Const) and
f.doc = stmt1.expr.value isinstance(stmt1.expr.value, str)):
f.doc = stmt1.expr.value
# The caller may specify that certain variables are globals # The caller may specify that certain variables are globals
# so that they can be referenced before a local assignment. # so that they can be referenced before a local assignment.
# The only known example is the variables context, container, # The only known example is the variables context, container,
......
...@@ -13,7 +13,7 @@ import unittest ...@@ -13,7 +13,7 @@ import unittest
from RestrictedPython import compile_restricted, PrintCollector from RestrictedPython import compile_restricted, PrintCollector
from RestrictedPython.Eval import RestrictionCapableEval from RestrictedPython.Eval import RestrictionCapableEval
from RestrictedPython.tests import before_and_after, restricted_module, verify from RestrictedPython.tests import before_and_after, restricted_module, verify
from RestrictedPython.RCompile import RModule from RestrictedPython.RCompile import RModule, RFunction
try: try:
__file__ __file__
...@@ -437,6 +437,12 @@ class RestrictionTests(unittest.TestCase): ...@@ -437,6 +437,12 @@ class RestrictionTests(unittest.TestCase):
co = self._compile_file("lambda.py") co = self._compile_file("lambda.py")
exec co in {}, {} 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): def checkSyntaxError(self):
err = ("def f(x, y):\n" err = ("def f(x, y):\n"
" if x, y < 2 + 1:\n" " if x, y < 2 + 1:\n"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment