Commit ecc60c81 authored by Chris McDonough's avatar Chris McDonough

Prevent 'render' function in Expressions.py for being called for basic types...

Prevent 'render' function in Expressions.py for being called for basic types (minor speed improvement).  See  http://www.zope.org/Collectors/Zope/1890. 
parent aaf3ff7c
...@@ -156,7 +156,9 @@ class PathExpr: ...@@ -156,7 +156,9 @@ class PathExpr:
return 0 return 0
def _eval(self, econtext, 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]: for expr in self._subexprs[:-1]:
# Try all but the last subexpression, skipping undefined ones. # Try all but the last subexpression, skipping undefined ones.
try: try:
...@@ -172,7 +174,7 @@ class PathExpr: ...@@ -172,7 +174,7 @@ class PathExpr:
if self._hybrid: if self._hybrid:
return ob return ob
if self._name == 'nocall' or isinstance(ob, StringType): if self._name == 'nocall' or isinstance(ob, BasicTypes):
return ob return ob
# Return the rendered object # Return the rendered object
return render(ob, econtext.vars) return render(ob, econtext.vars)
......
...@@ -4,6 +4,11 @@ from Products.PageTemplates import Expressions ...@@ -4,6 +4,11 @@ from Products.PageTemplates import Expressions
from Products.PageTemplates.DeferExpr import LazyWrapper from Products.PageTemplates.DeferExpr import LazyWrapper
from Products.PageTemplates.DeferExpr import DeferWrapper from Products.PageTemplates.DeferExpr import DeferWrapper
class Dummy:
__allow_access_to_unprotected_subobjects__ = 1
def __call__(self):
return 'dummy'
class ExpressionTests(unittest.TestCase): class ExpressionTests(unittest.TestCase):
def setUp(self): def setUp(self):
...@@ -12,6 +17,7 @@ class ExpressionTests(unittest.TestCase): ...@@ -12,6 +17,7 @@ class ExpressionTests(unittest.TestCase):
one = 1, one = 1,
d = {'one': 1, 'b': 'b', '': 'blank', '_': 'under'}, d = {'one': 1, 'b': 'b', '': 'blank', '_': 'under'},
blank = '', blank = '',
dummy = Dummy()
) )
def tearDown(self): def tearDown(self):
...@@ -36,6 +42,10 @@ class ExpressionTests(unittest.TestCase): ...@@ -36,6 +42,10 @@ class ExpressionTests(unittest.TestCase):
assert ec.evaluate('d/one') == 1 assert ec.evaluate('d/one') == 1
assert ec.evaluate('d/b') == 'b' assert ec.evaluate('d/b') == 'b'
def testRenderedEval(self):
ec = self.ec
assert ec.evaluate('dummy') == 'dummy'
def testEval1(self): def testEval1(self):
'''Test advanced expression evaluation 1''' '''Test advanced expression evaluation 1'''
ec = self.ec ec = self.ec
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment