[Zope-Checkins] SVN: Zope/branches/Zope-2_8-branch/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:07:03 EDT 2005


Log message for revision 38619:
  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/branches/Zope-2_8-branch/lib/python/Products/PageTemplates/Expressions.py
  U   Zope/branches/Zope-2_8-branch/lib/python/Products/PageTemplates/tests/testExpressions.py

-=-
Modified: Zope/branches/Zope-2_8-branch/lib/python/Products/PageTemplates/Expressions.py
===================================================================
--- Zope/branches/Zope-2_8-branch/lib/python/Products/PageTemplates/Expressions.py	2005-09-25 14:04:30 UTC (rev 38618)
+++ Zope/branches/Zope-2_8-branch/lib/python/Products/PageTemplates/Expressions.py	2005-09-25 14:07:02 UTC (rev 38619)
@@ -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/branches/Zope-2_8-branch/lib/python/Products/PageTemplates/tests/testExpressions.py
===================================================================
--- Zope/branches/Zope-2_8-branch/lib/python/Products/PageTemplates/tests/testExpressions.py	2005-09-25 14:04:30 UTC (rev 38618)
+++ Zope/branches/Zope-2_8-branch/lib/python/Products/PageTemplates/tests/testExpressions.py	2005-09-25 14:07:02 UTC (rev 38619)
@@ -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