[Zope3-checkins] SVN: Zope3/branches/3.3/ Fix http://www.zope.org/Collectors/Zope3-dev/638:

Philipp von Weitershausen philikon at philikon.de
Thu May 25 14:08:03 EDT 2006


Log message for revision 68281:
  Fix http://www.zope.org/Collectors/Zope3-dev/638:
    TALES PathExpr calls result of alternate subexpression
  
  This corresponds to issue 538 in Zope 2 and r22855 in the Zope 2 trunk.
  

Changed:
  U   Zope3/branches/3.3/doc/CHANGES.txt
  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/doc/CHANGES.txt
===================================================================
--- Zope3/branches/3.3/doc/CHANGES.txt	2006-05-25 17:51:17 UTC (rev 68280)
+++ Zope3/branches/3.3/doc/CHANGES.txt	2006-05-25 18:08:02 UTC (rev 68281)
@@ -10,6 +10,9 @@
 
     Bugfixes
 
+      - Fixed issue 638: TALES PathExpr calls result of alternate
+        subexpression
+
       - Fixed issue 635: TALES PathExpr doesn't call old style classes
 
       - Fixed issue 543: add 'decimal'-package to

Modified: Zope3/branches/3.3/src/zope/tales/expressions.py
===================================================================
--- Zope3/branches/3.3/src/zope/tales/expressions.py	2006-05-25 17:51:17 UTC (rev 68280)
+++ Zope3/branches/3.3/src/zope/tales/expressions.py	2006-05-25 18:08:02 UTC (rev 68281)
@@ -139,7 +139,6 @@
         return ob
 
 
-
 class PathExpr(object):
     """One or more subpath expressions, separated by '|'."""
     implements(ITALESExpression)
@@ -156,6 +155,7 @@
     def __init__(self, name, expr, engine, traverser=simpleTraverse):
         self._s = expr
         self._name = name
+        self._hybrid = False
         paths = expr.split('|')
         self._subexprs = []
         add = self._subexprs.append
@@ -165,6 +165,7 @@
                 # This part is the start of another expression type,
                 # so glue it back together and compile it.
                 add(engine.compile('|'.join(paths[i:]).lstrip()))
+                self._hybrid = True
                 break
             add(SubPathExpr(path, traverser, engine)._eval)
 
@@ -188,8 +189,11 @@
             else:
                 break
         else:
-            # On the last subexpression allow exceptions through.
+            # On the last subexpression allow exceptions through, and
+            # don't autocall if the expression was not a subpath.
             ob = self._subexprs[-1](econtext)
+            if self._hybrid:
+                return ob
 
         if self._name == 'nocall':
             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:51:17 UTC (rev 68280)
+++ Zope3/branches/3.3/src/zope/tales/tests/test_expressions.py	2006-05-25 18:08:02 UTC (rev 68281)
@@ -114,7 +114,7 @@
                              'Dynamic name specified in first subpath element')
         else:
             self.fail('Engine accepted first subpath element as dynamic')
-            
+
     def testOldStyleClassIsCalled(self):
         class AnOldStyleClass:
             pass
@@ -142,6 +142,11 @@
         context=self.context
         self.assertEqual(expr(context), 4)
 
+    def testPythonCallableIsntCalled(self):
+        self.context.vars['acallable'] = lambda: 23
+        expr = self.engine.compile('python: acallable')
+        self.assertEqual(expr(self.context), self.context.vars['acallable'])
+
     def testPythonNewline(self):
         expr = self.engine.compile('python: 2 \n+\n 2\n')
         context=self.context
@@ -156,6 +161,20 @@
         self.assertRaises(self.engine.getCompilerError(),
                           self.engine.compile, 'python: splat.0')
 
+    def testHybridPathExpressions(self):
+        def eval(expr):
+            e = self.engine.compile(expr)
+            return e(self.context)
+        self.context.vars['one'] = 1
+        self.context.vars['acallable'] = lambda: 23
+
+        self.assertEqual(eval('foo | python:1+1'), 2)
+        self.assertEqual(eval('foo | python:acallable'),
+                         self.context.vars['acallable'])
+        self.assertEqual(eval('foo | string:x'), 'x')
+        self.assertEqual(eval('foo | string:$one'), '1')
+        self.assert_(eval('foo | exists:x'))
+
     def testEmptyPathSegmentRaisesCompilerError(self):
         CompilerError = self.engine.getCompilerError()
         def check(expr):



More information about the Zope3-Checkins mailing list