[ZPT] CVS: Packages/Products/PageTemplates (Products/DC/PageTemplates) - Expressions.py:1.15
fred@digicool.com
fred@digicool.com
Thu, 7 Jun 2001 10:57:59 -0400 (EDT)
Update of /cvs-repository/Packages/Products/PageTemplates
In directory korak.digicool.com:/tmp/cvs-serv15708
Modified Files:
Expressions.py
Log Message:
PathExpr._eval():
Very aggressively cache anything that involves a global lookup.
restrictedTraverse():
Only cache things once it's possible we might use them. Use the
cached getattr() in one plase where the global was being looked up
again. Cache hasattr() as well. Only construct the marker (M)
once, not once for each call.
--- Updated File Expressions.py in package Packages/Products/PageTemplates --
--- Expressions.py 2001/05/22 18:47:33 1.14
+++ Expressions.py 2001/06/07 14:57:58 1.15
@@ -171,14 +171,15 @@
dp.reverse()
return base, path, dp
- def _eval(self, (base, path, dp), econtext):
+ def _eval(self, (base, path, dp), econtext,
+ list=list, isinstance=isinstance, StringType=type('')):
path = list(path) # Copy!
contexts = econtext.contexts
var = contexts['var']
# Expand dynamic path parts from right to left.
for i, varname in dp:
val = var[varname]
- if type(val) is type(''):
+ if isinstance(val, StringType):
path[i] = val
else:
# If the value isn't a string, assume it's a sequence
@@ -270,26 +271,24 @@
return '<NotExpr %s>' % `self._s`
-def restrictedTraverse(self, path):
+def restrictedTraverse(self, path,
+ get=getattr, has=hasattr, N=None, M=[]):
if not path: return self
- get=getattr
- N=None
- M=[] #marker
-
- REQUEST={'TraversalRequestNameStack': path}
securityManager = getSecurityManager()
- plen = len(path)
i = 0
if not path[0]:
# If the path starts with an empty string, go to the root first.
- i = 1
self = self.getPhysicalRoot()
if not securityManager.validateValue(self):
raise 'Unauthorized', name
-
+ i = 1
+
+ plen = len(path)
+ REQUEST={'TraversalRequestNameStack': path}
+ validate = securityManager.validate
object = self
while i < plen:
__traceback_info__ = (path, i)
@@ -301,9 +300,9 @@
raise AttributeError, name
if name=='..':
- o = getattr(object, 'aq_parent', M)
+ o = get(object, 'aq_parent', M)
if o is not M:
- if not securityManager.validate(object, object, name, o):
+ if not validate(object, object, name, o):
raise 'Unauthorized', name
object=o
continue
@@ -313,27 +312,27 @@
o=t(REQUEST, name)
container = None
- if (hasattr(get(object, 'aq_base', object), name)
+ if (has(get(object, 'aq_base', object), name)
and get(object, name) is o):
container = object
- if not securityManager.validate(object, container, name, o):
+ if not validate(object, container, name, o):
raise 'Unauthorized', name
else:
o=get(object, name, M)
if o is not M:
# Check security.
- if hasattr(object, 'aq_acquire'):
+ if has(object, 'aq_acquire'):
object.aq_acquire(
- name, validate2, securityManager.validate)
+ name, validate2, validate)
else:
- if not securityManager.validate(object, object, name, o):
+ if not validate(object, object, name, o):
raise 'Unauthorized', name
else:
try:
o=object[name]
except (AttributeError, TypeError):
raise AttributeError, name
- if not securityManager.validate(object, object, name, o):
+ if not validate(object, object, name, o):
raise 'Unauthorized', name
object = o