[Zope-Checkins] CVS: Zope2 - DT_In.py:1.48.4.2 DT_Let.py:1.6.110.1 DT_Util.py:1.72.18.4
shane@digicool.com
shane@digicool.com
Wed, 25 Apr 2001 16:27:07 -0400 (EDT)
Update of /cvs-repository/Zope2/lib/python/DocumentTemplate
In directory korak:/tmp/cvs-serv27222/lib/python/DocumentTemplate
Modified Files:
Tag: RestrictedPythonBranch
DT_In.py DT_Let.py DT_Util.py
Log Message:
Replaced references to VSEval and expr_globals with simple references to the
restricted Eval class in DT_Util.
--- Updated File DT_In.py in package Zope2 --
--- DT_In.py 2001/04/19 22:52:47 1.48.4.1
+++ DT_In.py 2001/04/25 20:26:35 1.48.4.2
@@ -406,8 +406,7 @@
__version__='$Revision$'[11:-2]
from DT_Util import ParseError, parse_params, name_param, str
-from DT_Util import render_blocks, InstanceDict, ValidationError, \
- RestrictedEval, expr_globals
+from DT_Util import render_blocks, InstanceDict, ValidationError, Eval
from string import find, atoi, join, split, lower
import ts_regex
from DT_InSV import sequence_variables, opt
@@ -446,11 +445,10 @@
if sort=='sequence-item': self.sort=''
if has_key('sort_expr'):
- self.sort_expr=RestrictedEval(args['sort_expr'], expr_globals)
+ self.sort_expr=Eval(args['sort_expr'])
if has_key('reverse_expr'):
- self.reverse_expr=RestrictedEval(args['reverse_expr'],
- expr_globals)
+ self.reverse_expr=Eval(args['reverse_expr'])
if has_key('reverse'):
self.reverse=args['reverse']
--- Updated File DT_Let.py in package Zope2 --
--- DT_Let.py 2000/07/05 15:28:12 1.6
+++ DT_Let.py 2001/04/25 20:26:35 1.6.110.1
@@ -112,7 +112,7 @@
as desired.
'''
-from DT_Util import render_blocks, Eval, expr_globals, ParseError, regex, strip
+from DT_Util import render_blocks, Eval, ParseError, regex, strip
from DT_Util import str # Probably needed due to hysterical pickles.
@@ -131,7 +131,7 @@
if expr[:1]=='"' and expr[-1:]=='"' and len(expr) > 1:
# expr shorthand
expr=expr[1:-1]
- try: args[i] = name, Eval(expr, expr_globals).eval
+ try: args[i] = name, Eval(expr).eval
except SyntaxError, v:
m,(huh,l,c,src) = v
raise ParseError, (
--- Updated File DT_Util.py in package Zope2 --
--- DT_Util.py 2001/04/20 17:42:24 1.72.18.3
+++ DT_Util.py 2001/04/25 20:26:35 1.72.18.4
@@ -87,7 +87,6 @@
import regex, string, math, os
from string import strip, join, atoi, lower, split, find
-##import VSEval
str=__builtins__['str'] # Waaaaa, waaaaaaaa needed for pickling waaaaa
@@ -157,33 +156,6 @@
except: pass
return 0
-##def careful_getitem(md, mapping, key):
-## v=mapping[key]
-
-## if type(v) is type(''): return v # Short-circuit common case
-
-## validate=md.validate
-## if validate is None or validate(mapping,mapping,None,v,md): return v
-## raise ValidationError, key
-
-##def careful_getslice(md, seq, *indexes):
-## v=len(indexes)
-## if v==2:
-## v=seq[indexes[0]:indexes[1]]
-## elif v==1:
-## v=seq[indexes[0]:]
-## else: v=seq[:]
-
-## if type(seq) is type(''): return v # Short-circuit common case
-
-## validate=md.validate
-## if validate is not None:
-## for e in v:
-## if not validate(seq,seq,None,e,md):
-## raise ValidationError, 'unauthorized access to slice member'
-
-## return v
-
def careful_range(md, iFirst, *args):
# limited range function from Martijn Pieters
RANGELIMIT = 1000
@@ -316,7 +288,7 @@
self._ob = ob
def __getattr__(self, name):
- if name[:1]!='_': # Shouldn't be necessary to check for _
+ if name[:1]!='_': # This condition is probably unnecessary.
inst = self._ob
# Try to get the attribute normally so that we don't
# accidentally acquire when we shouldn't.
@@ -362,35 +334,31 @@
raise ValidationError, (
'unauthorized access to slice member')
return v
-
-expr_globals={
- '__builtins__':{},
- }
-from RestrictedPython.Eval import RestrictedEval
+from RestrictedPython.Eval import RestrictionCapableEval
-class Eval(RestrictedEval):
+class Eval(RestrictionCapableEval):
- def eval(self, mapping):
- d = {'_': mapping}
+ def eval(self, md):
# Create a temporary subclass of DTMLGuard.
class Guard (DTMLGuard): pass
- Guard._md = mapping
- globals = self.globals.copy()
- globals['_guard'] = Guard
- code = self.code
+ Guard._md = md
+ d = {'_': md, '_read_guard': Guard}
for name in self.used:
__traceback_info__ = name
- try: d[name]=mapping.getitem(name,0)
+ try: d[name] = md.getitem(name,0)
except KeyError:
# Swallow KeyErrors since the expression
# might not actually need the name. If it
# does need the name, a NameError will occur.
pass
- return eval(code, globals, d)
+ return eval(self.code, self.globals, d)
- def __call__(self, *args, **kw):
- raise 'NotImplemented', 'Ignorant Digital Creations developer error'
+ def __call__(self, **kw):
+ # Never used?
+ md = TemplateDict()
+ md._push(kw)
+ return self.eval(md)
def name_param(params,tag='',expr=0, attr='name', default_unnamed=1):
@@ -412,7 +380,7 @@
if used('expr'):
raise ParseError, ('two exprs given', tag)
v=v[1:-1]
- try: expr=Eval(v, expr_globals)
+ try: expr=Eval(v)
except SyntaxError, v:
raise ParseError, (
'<strong>Expression (Python) Syntax error</strong>:'
@@ -442,7 +410,7 @@
return params[attr]
elif expr and used('expr'):
name=params['expr']
- expr=Eval(name, expr_globals)
+ expr=Eval(name)
return name, expr
raise ParseError, ('No %s given' % attr, tag)