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:
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 @@ class PathExpr:
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)
......
......@@ -4,6 +4,11 @@ from Products.PageTemplates import Expressions
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 @@ class ExpressionTests(unittest.TestCase):
one = 1,
d = {'one': 1, 'b': 'b', '': 'blank', '_': 'under'},
blank = '',
dummy = Dummy()
)
def tearDown(self):
......@@ -36,6 +42,10 @@ class ExpressionTests(unittest.TestCase):
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
......
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