[Checkins] SVN: z3c.pt/trunk/z3c/pt/expressions.py Ignore strings,
tuples and lists when proxifying;
attributes have priority and are always called.
Malthe Borch
mborch at gmail.com
Tue Mar 18 21:44:45 EDT 2008
Log message for revision 84770:
Ignore strings, tuples and lists when proxifying; attributes have priority and are always called.
Changed:
U z3c.pt/trunk/z3c/pt/expressions.py
-=-
Modified: z3c.pt/trunk/z3c/pt/expressions.py
===================================================================
--- z3c.pt/trunk/z3c/pt/expressions.py 2008-03-19 00:51:20 UTC (rev 84769)
+++ z3c.pt/trunk/z3c/pt/expressions.py 2008-03-19 01:44:45 UTC (rev 84770)
@@ -2,18 +2,20 @@
import zope.interface
import zope.component
+import zope.security
+import zope.security.proxy
import zope.traversing.adapters
-import zope.security.proxy
import parser
import re
-from interfaces import IExpressionTranslation
-
+import interfaces
import types
+_marker = object()
+
class ExpressionTranslation(object):
- zope.interface.implements(IExpressionTranslation)
+ zope.interface.implements(interfaces.IExpressionTranslation)
re_pragma = re.compile(r'^\s*(?P<pragma>[a-z]+):\s*')
re_interpolation = re.compile(r'(?P<prefix>[^\\]\$|^\$){((?P<expression>.*)})?')
@@ -300,9 +302,9 @@
translator = \
zope.component.queryUtility(
- IExpressionTranslation, name=pragma) or \
+ interfaces.IExpressionTranslation, name=pragma) or \
zope.component.queryAdapter(
- self, IExpressionTranslation, name=pragma) or \
+ self, interfaces.IExpressionTranslation, name=pragma) or \
self
if translator is not self:
@@ -395,7 +397,7 @@
return types.value(string)
class StringTranslation(ExpressionTranslation):
- zope.component.adapts(IExpressionTranslation)
+ zope.component.adapts(interfaces.IExpressionTranslation)
def __init__(self, translator):
self.translator = translator
@@ -472,21 +474,30 @@
def traverse(cls, base, request, call, *path_items):
"""See ``zope.app.pagetemplate.engine``."""
+ _callable = callable(base)
+
for i in range(len(path_items)):
name = path_items[i]
-
- # special-case dicts for performance reasons
- if getattr(base, '__class__', None) == dict:
- base = base[name]
+
+ next = getattr(base, name, _marker)
+ if next is not _marker:
+ base = next()
else:
- base = zope.traversing.adapters.traversePathElement(
- base, name, path_items[i+1:], request=request)
-
- base = zope.security.proxy.ProxyFactory(base)
+ # 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)
- if call and callable(base):
+ _callable = callable(base)
+
+ if not isinstance(base, (basestring, tuple, list)):
+ base = zope.security.proxy.ProxyFactory(base)
+
+ if call and _callable:
base = base()
-
+
return base
def validate(self, string):
More information about the Checkins
mailing list