[Zope-Checkins] CVS: Zope2 - Eval.py:1.1.2.8
shane@digicool.com
shane@digicool.com
Fri, 27 Apr 2001 11:19:42 -0400 (EDT)
Update of /cvs-repository/Zope2/lib/python/RestrictedPython
In directory korak:/tmp/cvs-serv19956
Modified Files:
Tag: RestrictedPythonBranch
Eval.py
Log Message:
Added comments and used "None" for the default builtins, which is rumored
to be safer... :-/
--- Updated File Eval.py in package Zope2 --
--- Eval.py 2001/04/26 22:20:26 1.1.2.7
+++ Eval.py 2001/04/27 15:19:41 1.1.2.8
@@ -102,7 +102,7 @@
class RestrictionCapableEval:
"""A base class for restricted code.
"""
- globals = {'__builtins__': {}}
+ globals = {'__builtins__': None}
rcode = None # restricted
ucode = None # unrestricted
used = None
@@ -113,8 +113,6 @@
where:
expr -- a string containing the expression to be evaluated.
-
- globals -- A global namespace.
"""
expr = strip(expr)
self.__name__ = expr
@@ -145,8 +143,11 @@
def prepUnrestrictedCode(self):
if self.ucode is None:
+ # Use the standard compiler.
co = compile(self.expr, '<string>', 'eval')
if self.used is None:
+ # Examine the code object, discovering which names
+ # the expression needs.
names=list(co.co_names)
used={}
i=0
@@ -166,6 +167,8 @@
self.ucode=co
def eval(self, mapping):
+ # This default implementation is probably not very useful. :-(
+ # This is meant to be overridden.
self.prepRestrictedCode()
code = self.rcode
d = {'_read_': default_read_guard}