[Zope-Checkins] CVS: Packages/RestrictedPython - RCompile.py:1.4
RCompile_2_1.py:1.4
Evan Simpson
cvs-admin at zope.org
Tue Nov 4 16:07:44 EST 2003
Update of /cvs-repository/Packages/RestrictedPython
In directory cvs.zope.org:/tmp/cvs-serv15905/lib/python/RestrictedPython
Modified Files:
RCompile.py RCompile_2_1.py
Log Message:
Collector #445: Add internal global declaration for Script bindings.
=== Packages/RestrictedPython/RCompile.py 1.3 => 1.4 ===
--- Packages/RestrictedPython/RCompile.py:1.3 Wed Aug 14 17:44:31 2002
+++ Packages/RestrictedPython/RCompile.py Tue Nov 4 16:07:44 2003
@@ -79,10 +79,11 @@
"""A restricted Python function built from parts.
"""
- def __init__(self, p, body, name, filename):
+ def __init__(self, p, body, name, filename, globalize=None):
self.params = p
self.body = body
self.name = name
+ self.globalize = globalize
RModule.__init__(self, None, filename)
def parse(self):
@@ -100,6 +101,8 @@
isinstance(stmt1.expr, ast.Const) and
type(stmt1.expr.value) is type('')):
f.doc = stmt1.expr.value
+ if self.globalize:
+ f.code.nodes.insert(0, ast.Global(map(str, self.globalize)))
return tree
@@ -110,14 +113,14 @@
return None, (str(v),), gen.rm.warnings, gen.rm.used_names
return gen.getCode(), (), gen.rm.warnings, gen.rm.used_names
-def compile_restricted_function(p, body, name, filename):
+def compile_restricted_function(p, body, name, filename, globalize=None):
"""Compiles a restricted code object for a function.
The function can be reconstituted using the 'new' module:
new.function(<code>, <globals>)
"""
- gen = RFunction(p, body, name, filename)
+ gen = RFunction(p, body, name, filename, globalize=globalize)
return compileAndTuplize(gen)
def compile_restricted_exec(s, filename='<string>'):
=== Packages/RestrictedPython/RCompile_2_1.py 1.3 => 1.4 ===
--- Packages/RestrictedPython/RCompile_2_1.py:1.3 Wed Aug 14 17:44:31 2002
+++ Packages/RestrictedPython/RCompile_2_1.py Tue Nov 4 16:07:44 2003
@@ -43,7 +43,7 @@
from RestrictionMutator import RestrictionMutator
from compiler_2_1 import ast, visitor, pycodegen
-def compile_restricted_function(p, body, name, filename):
+def compile_restricted_function(p, body, name, filename, globalize=None):
'''Compile a restricted code object for a function.
The function can be reconstituted using the 'new' module:
@@ -63,6 +63,8 @@
f = tree.node.nodes[0]
btree, err = tryParsing(body, 'exec')
if err: return err
+ if globalize is not None:
+ btree.node.nodes.insert(0, ast.Global(map(str, globalize)))
f.code.nodes = btree.node.nodes
f.name = name
# Look for a docstring
More information about the Zope-Checkins
mailing list