[ZPT] CVS: Packages/Products/PageTemplates (Products/DC/PageTemplates) - Expressions.py:1.16
fred@digicool.com
fred@digicool.com
Fri, 8 Jun 2001 16:59:26 -0400 (EDT)
Update of /cvs-repository/Packages/Products/PageTemplates
In directory korak.digicool.com:/tmp/cvs-serv20739
Modified Files:
Expressions.py
Log Message:
Micro-optimization to avoid function calls.
--- Updated File Expressions.py in package Packages/Products/PageTemplates --
--- Expressions.py 2001/06/07 14:57:58 1.15
+++ Expressions.py 2001/06/08 20:59:26 1.16
@@ -171,7 +171,7 @@
dp.reverse()
return base, path, dp
- def _eval(self, (base, path, dp), econtext,
+ def _eval(self, (base, path, dp), econtext, securityManager,
list=list, isinstance=isinstance, StringType=type('')):
path = list(path) # Copy!
contexts = econtext.contexts
@@ -193,14 +193,18 @@
has, ob = var.has_get(base)
if not has:
ob = contexts[base]
- return restrictedTraverse(ob, path)
+ if path:
+ return restrictedTraverse(ob, path, securityManager)
+ else:
+ return ob
except (AttributeError, KeyError, TypeError, IndexError,
'Unauthorized'), e:
return Undefined(self._s, sys.exc_info())
def __call__(self, econtext):
+ securityManager = getSecurityManager()
for pathinfo in self._paths:
- ob = self._eval(pathinfo, econtext)
+ ob = self._eval(pathinfo, econtext, securityManager)
exists = not isinstance(ob, Undefined)
if exists:
@@ -271,13 +275,9 @@
return '<NotExpr %s>' % `self._s`
-def restrictedTraverse(self, path,
+def restrictedTraverse(self, path, securityManager,
get=getattr, has=hasattr, N=None, M=[]):
- if not path: return self
-
- securityManager = getSecurityManager()
-
i = 0
if not path[0]:
# If the path starts with an empty string, go to the root first.