[Checkins] SVN: five.pt/trunk/ Rework the "full namespace provided to path expression" change introduced in 0.3. We no longer call the expensive locals() function but construct a minimal namespace with the context and request ourselves.

Hanno Schlichting plone at hannosch.info
Mon Feb 16 12:37:30 EST 2009


Log message for revision 96594:
  Rework the "full namespace provided to path expression" change introduced in 0.3. We no longer call the expensive locals() function but construct a minimal namespace with the context and request ourselves.
  

Changed:
  U   five.pt/trunk/CHANGES.txt
  U   five.pt/trunk/buildout.cfg
  U   five.pt/trunk/src/five/pt/expressions.py

-=-
Modified: five.pt/trunk/CHANGES.txt
===================================================================
--- five.pt/trunk/CHANGES.txt	2009-02-16 17:30:16 UTC (rev 96593)
+++ five.pt/trunk/CHANGES.txt	2009-02-16 17:37:29 UTC (rev 96594)
@@ -1,6 +1,10 @@
 Changelog
 =========
 
+- Rework the "full namespace provided to path expression" change introduced
+  in 0.3. We no longer call the expensive locals() function but construct a
+  minimal namespace with the context and request ourselves. [hannosch]
+
 - If the ``__get__`` method is called uninstantiated, just return the
   class itself. [malthe]
 

Modified: five.pt/trunk/buildout.cfg
===================================================================
--- five.pt/trunk/buildout.cfg	2009-02-16 17:30:16 UTC (rev 96593)
+++ five.pt/trunk/buildout.cfg	2009-02-16 17:37:29 UTC (rev 96594)
@@ -24,12 +24,12 @@
 [versions]
 zope.testing = 3.7.1
 zope.i18n = 3.6.0
-lxml = 2.1.3
+lxml = 2.1.5
 setuptools = 0.6c9
 
 [lxml]
 recipe = z3c.recipe.staticlxml
-egg = lxml>=2.1.3
+egg = lxml>=2.1.5
 
 [test]
 recipe = zc.recipe.testrunner<1.1dev

Modified: five.pt/trunk/src/five/pt/expressions.py
===================================================================
--- five.pt/trunk/src/five/pt/expressions.py	2009-02-16 17:30:16 UTC (rev 96593)
+++ five.pt/trunk/src/five/pt/expressions.py	2009-02-16 17:37:29 UTC (rev 96594)
@@ -3,16 +3,18 @@
 from z3c.pt.expressions import ZopeExistsTraverser
 from z3c.pt.expressions import ProviderTranslator
 
+from Acquisition import aq_base
+from OFS.interfaces import ITraversable
+from Products.PageTemplates import ZRPythonExpr
 from zExceptions import NotFound, Unauthorized
-from OFS.interfaces import ITraversable
 
 from zope import component
+from zope.proxy import removeAllProxies
 from zope.traversing.adapters import traversePathElement
 from zope.traversing.interfaces import TraversalError
 from zope.contentprovider.interfaces import IContentProvider
 from zope.contentprovider.interfaces import ContentProviderLookupError
 
-from Products.PageTemplates.Expressions import render
 
 _marker = object()
 
@@ -21,9 +23,39 @@
     AQ_WRAP_CP = True
 except ImportError:
     AQ_WRAP_CP = False
-    
+
+
+def render(ob, request):
+    """Calls the object, possibly a document template, or just returns
+    it if not callable.  (From Products.PageTemplates.Expressions.py)
+    """
+    # We are only different in the next line. The original function gets a
+    # dict-ish namespace passed in, we fake it.
+    # ZRPythonExpr.call_with_ns expects to get such a dict
+    ns = dict(context=ob, request=request)
+
+    if hasattr(ob, '__render_with_namespace__'):
+        ob = ZRPythonExpr.call_with_ns(ob.__render_with_namespace__, ns)
+    else:
+        # items might be acquisition wrapped
+        base = aq_base(ob)
+        # item might be proxied (e.g. modules might have a deprecation
+        # proxy)
+        base = removeAllProxies(base)
+        if callable(base):
+            try:
+                if getattr(base, 'isDocTemp', 0):
+                    ob = ZRPythonExpr.call_with_ns(ob, ns, 2)
+                else:
+                    ob = ob()
+            except AttributeError, n:
+                if str(n) != '__call__':
+                    raise
+    return ob
+
+
 class FiveTraverser(object):
-    def __call__(self, base, scope, call, *path_items):
+    def __call__(self, base, request, call, *path_items):
         """See ``zope.app.pagetemplate.engine``."""
 
         length = len(path_items)
@@ -44,7 +76,7 @@
                         base = base.restrictedTraverse(name)
                     else:
                         base = traversePathElement(
-                            base, name, path_items[i:], request=scope['request'])
+                            base, name, path_items[i:], request=request)
 
         if call is False:
             return base
@@ -52,13 +84,12 @@
         if getattr(base, '__call__', _marker) is not _marker or callable(base):
             # here's where we're different from the standard path
             # traverser
-            base = render(base, scope)
+            base = render(base, request)
 
         return base
 
 class PathTranslator(PathTranslator):
     path_traverse = FiveTraverser()
-    scope = 'locals()'
 
 class FiveExistsTraverser(ZopeExistsTraverser):
     exceptions = AttributeError, LookupError, TypeError, \



More information about the Checkins mailing list