[ZPT] CVS: Zope/lib/python/Products/PageTemplates - Expressions.py:1.40 PageTemplate.py:1.29 PythonExpr.py:1.10 TALES.py:1.33

Florent Guillaume fg@nuxeo.com
Thu, 19 Sep 2002 10:39:25 -0400


Update of /cvs-repository/Zope/lib/python/Products/PageTemplates
In directory cvs.zope.org:/tmp/cvs-serv12623/lib/python/Products/PageTemplates

Modified Files:
	Expressions.py PageTemplate.py PythonExpr.py TALES.py 
Log Message:
Merged Fred's latest TAL/ZPT optimizations from Zope27 into HEAD.
The merge point in Zope27 will be tagged mergepoint-to-Zope26.


=== Zope/lib/python/Products/PageTemplates/Expressions.py 1.39 => 1.40 ===
--- Zope/lib/python/Products/PageTemplates/Expressions.py:1.39	Wed Sep 18 11:49:00 2002
+++ Zope/lib/python/Products/PageTemplates/Expressions.py	Thu Sep 19 10:39:24 2002
@@ -46,6 +46,8 @@
 
 if sys.modules.has_key('Zope'):
     import AccessControl
+    import AccessControl.cAccessControl
+    acquisition_security_filter = AccessControl.cAccessControl.aq_validate
     from AccessControl import getSecurityManager
     from AccessControl.ZopeGuards import guarded_getattr
     try:
@@ -65,6 +67,12 @@
         from zExceptions import Unauthorized
     except ImportError:
         Unauthorized = "Unauthorized"
+
+    def acquisition_security_filter(orig, inst, name, v, real_validate):
+        if real_validate(orig, inst, name, v):
+            return 1
+        raise Unauthorized, name
+
     def call_with_ns(f, ns, arg=1):
         if arg==2:
             return f(None, ns)
@@ -279,28 +287,27 @@
         return 'defer:%s' % `self._s`
 
 
-def restrictedTraverse(self, path, securityManager,
+def restrictedTraverse(object, path, securityManager,
                        get=getattr, has=hasattr, N=None, M=[],
                        TupleType=type(()) ):
 
-    REQUEST = {'path': path}
-    REQUEST['TraversalRequestNameStack'] = path = path[:] # Copy!
     if not path[0]:
         # If the path starts with an empty string, go to the root first.
-        self = self.getPhysicalRoot()
-        if not securityManager.validateValue(self):
+        object = object.getPhysicalRoot()
+        if not securityManager.validateValue(object):
             raise Unauthorized, name
         path.pop(0)
 
+    REQUEST = {'path': path}
+    REQUEST['TraversalRequestNameStack'] = path = path[:] # Copy!
     path.reverse()
     validate = securityManager.validate
-    object = self
+    __traceback_info__ = REQUEST
     while path:
-        __traceback_info__ = REQUEST
         name = path.pop()
 
         if isinstance(name, TupleType):
-            object = apply(object, name)
+            object = object(*name)
             continue
 
         if name[0] == '_':
@@ -363,9 +370,3 @@
         object = o
 
     return object
-
-
-def validate2(orig, inst, name, v, real_validate):
-    if not real_validate(orig, inst, name, v):
-        raise Unauthorized, name
-    return 1


=== Zope/lib/python/Products/PageTemplates/PageTemplate.py 1.28 => 1.29 ===
--- Zope/lib/python/Products/PageTemplates/PageTemplate.py:1.28	Wed Sep 18 11:12:46 2002
+++ Zope/lib/python/Products/PageTemplates/PageTemplate.py	Thu Sep 19 10:39:24 2002
@@ -22,10 +22,9 @@
 from TAL.TALParser import TALParser
 from TAL.HTMLTALParser import HTMLTALParser
 from TAL.TALGenerator import TALGenerator
-from TAL.TALInterpreter import TALInterpreter
-from Expressions import getEngine
 # Do not use cStringIO here!  It's not unicode aware. :(
-from StringIO import StringIO
+from TAL.TALInterpreter import TALInterpreter, FasterStringIO
+from Expressions import getEngine
 from ExtensionClass import Base
 from ComputedAttribute import ComputedAttribute
 
@@ -47,7 +46,7 @@
     def StringIO(self):
         # Third-party products wishing to provide a full Unicode-aware
         # StringIO can do so by monkey-patching this method.
-        return StringIO()
+        return FasterStringIO()
 
     def macros(self):
         return self.pt_macros()


=== Zope/lib/python/Products/PageTemplates/PythonExpr.py 1.9 => 1.10 ===
--- Zope/lib/python/Products/PageTemplates/PythonExpr.py:1.9	Wed Sep 18 11:12:46 2002
+++ Zope/lib/python/Products/PageTemplates/PythonExpr.py	Thu Sep 19 10:39:24 2002
@@ -43,18 +43,19 @@
             if vname[0] not in '$_':
                 vnames.append(vname)
 
-    def _bind_used_names(self, econtext):
+    def _bind_used_names(self, econtext, _marker=[]):
         # Bind template variables
         names = {}
         vars = econtext.vars
         getType = econtext._engine.getTypes().get
         for vname in self._f_varnames:
-            has, val = vars.has_get(vname)
-            if not has:
+            val = vars.get(vname, _marker)
+            if val is _marker:
                 has = val = getType(vname)
                 if has:
                     val = ExprTypeProxy(vname, val, econtext)
-            if has:
+                    names[vname] = val
+            else:
                 names[vname] = val
         return names
 


=== Zope/lib/python/Products/PageTemplates/TALES.py 1.32 => 1.33 ===
--- Zope/lib/python/Products/PageTemplates/TALES.py:1.32	Wed Sep 18 11:12:46 2002
+++ Zope/lib/python/Products/PageTemplates/TALES.py	Thu Sep 19 10:39:24 2002
@@ -44,8 +44,6 @@
     '''Retain Default'''
 Default = Default()
 
-_marker = []
-
 class SafeMapping(MultiMapping):
     '''Mapping with security declarations and limited method exposure.
 
@@ -60,9 +58,6 @@
     _push = MultiMapping.push
     _pop = MultiMapping.pop
 
-    def has_get(self, key, _marker=[]):
-        v = self.get(key, _marker)
-        return v is not _marker, v
 
 class Iterator(ZTUtils.Iterator):
     def __init__(self, name, seq, context):
@@ -216,8 +211,7 @@
             expression = self._engine.compile(expression)
         __traceback_supplement__ = (
             TALESTracebackSupplement, self, expression)
-        v = expression(self)
-        return v
+        return expression(self)
 
     evaluateValue = evaluate
 
@@ -257,7 +251,6 @@
             domain, msgid, mapping=mapping,
             context=context, target_language=target_language)
 
-
 class TALESTracebackSupplement:
     """Implementation of ITracebackSupplement"""
     def __init__(self, context, expression):
@@ -276,8 +269,6 @@
         else:
             from cgi import escape
             return '<b>Names:</b><pre>%s</pre>' % (escape(s))
-        return None
-
 
 
 class SimpleExpr:
@@ -289,4 +280,3 @@
         return self._name, self._expr
     def __repr__(self):
         return '<SimpleExpr %s %s>' % (self._name, `self._expr`)
-