[Checkins] SVN: z3c.pt/trunk/ The default path traverser no longer proxies objects.

Malthe Borch mborch at gmail.com
Mon Sep 8 11:45:27 EDT 2008


Log message for revision 90954:
  The default path traverser no longer proxies objects.

Changed:
  U   z3c.pt/trunk/CHANGES.txt
  U   z3c.pt/trunk/setup.py
  U   z3c.pt/trunk/src/z3c/pt/expressions.py

-=-
Modified: z3c.pt/trunk/CHANGES.txt
===================================================================
--- z3c.pt/trunk/CHANGES.txt	2008-09-08 15:41:05 UTC (rev 90953)
+++ z3c.pt/trunk/CHANGES.txt	2008-09-08 15:45:26 UTC (rev 90954)
@@ -6,6 +6,8 @@
 
   Backwards incompatibilities
 
+- The default path traverser no longer proxies objects. [malthe]
+  
 - Template output is now always converted to unicode. [malthe]
   
 - The ``ViewPageTemplateFile`` class now uses 'path' as the default

Modified: z3c.pt/trunk/setup.py
===================================================================
--- z3c.pt/trunk/setup.py	2008-09-08 15:41:05 UTC (rev 90953)
+++ z3c.pt/trunk/setup.py	2008-09-08 15:45:26 UTC (rev 90954)
@@ -8,7 +8,6 @@
     'zope.component',
     'zope.i18n >= 3.5',
     'zope.traversing',
-    'zope.security',
     ]
 
 if sys.version_info[:3] < (2,5,0):

Modified: z3c.pt/trunk/src/z3c/pt/expressions.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/expressions.py	2008-09-08 15:41:05 UTC (rev 90953)
+++ z3c.pt/trunk/src/z3c/pt/expressions.py	2008-09-08 15:45:26 UTC (rev 90954)
@@ -1,7 +1,5 @@
 import zope.interface
 import zope.component
-import zope.security
-import zope.security.proxy
 import zope.traversing.adapters
 
 import parser
@@ -643,11 +641,50 @@
         
         return string.replace(';;', ';')
 
+class ZopeTraverser(object):
+    def __init__(self, proxify=None):
+        if proxify is None:
+            self.proxify = lambda x: x
+        else:
+            self.proxify = proxify
+
+    def __call__(self, base, request, call, *path_items):
+        """See ``zope.app.pagetemplate.engine``."""
+
+        _callable = getattr(base, '__call__', _marker) is not _marker
+
+        for i in range(len(path_items)):
+            name = path_items[i]
+
+            next = getattr(base, name, _marker)
+            if next is not _marker:
+                _callable = getattr(next, '__call__', _marker) is not _marker
+                base = next
+                continue
+            else:
+                # special-case dicts for performance reasons        
+                if getattr(base, '__class__', None) == dict:
+                    base = base[name]
+                else:
+                    base = zope.traversing.adapters.traversePathElement(
+                        base, name, path_items[i+1:], request=request)
+
+            _callable = getattr(base, '__call__', _marker) is not _marker
+
+            if not isinstance(base, (basestring, tuple, list)):
+                base = self.proxify(base)
+
+        if call and _callable:
+            base = base()
+
+        return base
+
 class PathTranslation(ExpressionTranslation):
     path_regex = re.compile(
         r'^((nocall|not):\s*)*([A-Za-z_][A-Za-z0-9_]*)'+
         r'(/[A-Za-z_ at -][A-Za-z0-9_ at -\\.]*)*$')
 
+    path_traverse = ZopeTraverser()
 
     def validate(self, string):
         if not self.path_regex.match(string.strip()):
@@ -706,39 +743,8 @@
         if negate:
             value = types.value('not(%s)' % value)
 
-        value.symbol_mapping[config.SYMBOLS.path] = path_traverse
+        value.symbol_mapping[config.SYMBOLS.path] = self.path_traverse
 
         return value
 
-def path_traverse(base, request, call, *path_items):
-    """See ``zope.app.pagetemplate.engine``."""
-
-    _callable = callable(base)
-
-    for i in range(len(path_items)):
-        name = path_items[i]
-
-        next = getattr(base, name, _marker)
-        if next is not _marker:
-            _callable = callable(next)
-            base = next
-            continue
-        else:
-            # special-case dicts for performance reasons        
-            if getattr(base, '__class__', None) == dict:
-                base = base[name]
-            else:
-                base = zope.traversing.adapters.traversePathElement(
-                    base, name, path_items[i+1:], request=request)
-
-        _callable = callable(base)
-
-        if not isinstance(base, (basestring, tuple, list)):
-            base = zope.security.proxy.ProxyFactory(base)
-
-    if call and _callable:
-        base = base()
-
-    return base
-
 path_translation = PathTranslation()



More information about the Checkins mailing list