[Zope3-checkins] SVN: Zope3/branches/3.3/src/zope/tales/ Fix
http://www.zope.org/Collectors/Zope3-dev/635:
Philipp von Weitershausen
philikon at philikon.de
Thu May 25 13:50:09 EDT 2006
Log message for revision 68279:
Fix http://www.zope.org/Collectors/Zope3-dev/635:
TALES PathExpr doesn't calls old style classes
Changed:
U Zope3/branches/3.3/src/zope/tales/expressions.py
U Zope3/branches/3.3/src/zope/tales/tests/test_expressions.py
-=-
Modified: Zope3/branches/3.3/src/zope/tales/expressions.py
===================================================================
--- Zope3/branches/3.3/src/zope/tales/expressions.py 2006-05-25 17:49:12 UTC (rev 68278)
+++ Zope3/branches/3.3/src/zope/tales/expressions.py 2006-05-25 17:50:09 UTC (rev 68279)
@@ -15,7 +15,7 @@
$Id$
"""
-import re
+import re, types
from zope.interface import implements
from zope.tales.tales import _valid_name, _parse_expr, NAME_RE, Undefined
@@ -194,8 +194,16 @@
if self._name == 'nocall':
return ob
- # Call the object if it is callable.
- if hasattr(ob, '__call__'):
+ # Call the object if it is callable. Note that checking for
+ # callable() isn't safe because the object might be security
+ # proxied (and security proxies report themselves callable, no
+ # matter what the underlying object is). We therefore check
+ # for the __call__ attribute, but not with hasattr as that
+ # eats babies, err, exceptions. In addition to that, we
+ # support calling old style classes which don't have a
+ # __call__.
+ if (getattr(ob, '__call__', _marker) is not _marker
+ or isinstance(ob, types.ClassType)):
return ob()
return ob
Modified: Zope3/branches/3.3/src/zope/tales/tests/test_expressions.py
===================================================================
--- Zope3/branches/3.3/src/zope/tales/tests/test_expressions.py 2006-05-25 17:49:12 UTC (rev 68278)
+++ Zope3/branches/3.3/src/zope/tales/tests/test_expressions.py 2006-05-25 17:50:09 UTC (rev 68279)
@@ -115,6 +115,13 @@
else:
self.fail('Engine accepted first subpath element as dynamic')
+ def testOldStyleClassIsCalled(self):
+ class AnOldStyleClass:
+ pass
+ self.context.vars['oldstyleclass'] = AnOldStyleClass
+ expr = self.engine.compile('oldstyleclass')
+ self.assert_(isinstance(expr(self.context), AnOldStyleClass))
+
def testString(self):
expr = self.engine.compile('string:Fred')
context=self.context
More information about the Zope3-Checkins
mailing list