[Zope-Checkins] SVN: Zope/trunk/lib/python/Products/PageTemplates/
Prevent 'render' function in Expressions.py for being called
for basic types (minor speed improvement). See
http://www.zope.org/Collectors/Zope/1890.
Chris McDonough
chrism at plope.com
Sun Sep 25 10:04:30 EDT 2005
Log message for revision 38618:
Prevent 'render' function in Expressions.py for being called for basic types (minor speed improvement). See http://www.zope.org/Collectors/Zope/1890.
Changed:
U Zope/trunk/lib/python/Products/PageTemplates/Expressions.py
U Zope/trunk/lib/python/Products/PageTemplates/tests/testExpressions.py
-=-
Modified: Zope/trunk/lib/python/Products/PageTemplates/Expressions.py
===================================================================
--- Zope/trunk/lib/python/Products/PageTemplates/Expressions.py 2005-09-25 13:47:37 UTC (rev 38617)
+++ Zope/trunk/lib/python/Products/PageTemplates/Expressions.py 2005-09-25 14:04:30 UTC (rev 38618)
@@ -156,7 +156,9 @@
return 0
def _eval(self, econtext,
- isinstance=isinstance, StringType=type(''), render=render):
+ isinstance=isinstance,
+ BasicTypes=(str, unicode, dict, list, tuple, bool),
+ render=render):
for expr in self._subexprs[:-1]:
# Try all but the last subexpression, skipping undefined ones.
try:
@@ -172,7 +174,7 @@
if self._hybrid:
return ob
- if self._name == 'nocall' or isinstance(ob, StringType):
+ if self._name == 'nocall' or isinstance(ob, BasicTypes):
return ob
# Return the rendered object
return render(ob, econtext.vars)
Modified: Zope/trunk/lib/python/Products/PageTemplates/tests/testExpressions.py
===================================================================
--- Zope/trunk/lib/python/Products/PageTemplates/tests/testExpressions.py 2005-09-25 13:47:37 UTC (rev 38617)
+++ Zope/trunk/lib/python/Products/PageTemplates/tests/testExpressions.py 2005-09-25 14:04:30 UTC (rev 38618)
@@ -4,6 +4,11 @@
from Products.PageTemplates.DeferExpr import LazyWrapper
from Products.PageTemplates.DeferExpr import DeferWrapper
+class Dummy:
+ __allow_access_to_unprotected_subobjects__ = 1
+ def __call__(self):
+ return 'dummy'
+
class ExpressionTests(unittest.TestCase):
def setUp(self):
@@ -12,6 +17,7 @@
one = 1,
d = {'one': 1, 'b': 'b', '': 'blank', '_': 'under'},
blank = '',
+ dummy = Dummy()
)
def tearDown(self):
@@ -36,6 +42,10 @@
assert ec.evaluate('d/one') == 1
assert ec.evaluate('d/b') == 'b'
+ def testRenderedEval(self):
+ ec = self.ec
+ assert ec.evaluate('dummy') == 'dummy'
+
def testEval1(self):
'''Test advanced expression evaluation 1'''
ec = self.ec
More information about the Zope-Checkins
mailing list