[Zope3-checkins] SVN: Zope3/trunk/src/zope/tales/ Merged from jim-adapter branch:

Jim Fulton jim at zope.com
Fri Apr 7 08:08:49 EDT 2006


Log message for revision 66636:
  Merged from jim-adapter branch:
  
  Log message for revision 66358:
    The tales path expression "|" now catches LookupError, rather than
    IndexError and KeyError.  This is more inclusive and is needed to deal
    with exceptions that used to extend NotFoundError, which is now gone.
  

Changed:
  U   Zope3/trunk/src/zope/tales/expressions.py
  U   Zope3/trunk/src/zope/tales/tests/test_expressions.py

-=-
Modified: Zope3/trunk/src/zope/tales/expressions.py
===================================================================
--- Zope3/trunk/src/zope/tales/expressions.py	2006-04-07 11:19:19 UTC (rev 66635)
+++ Zope3/trunk/src/zope/tales/expressions.py	2006-04-07 12:08:49 UTC (rev 66636)
@@ -21,7 +21,7 @@
 from zope.tales.tales import _valid_name, _parse_expr, NAME_RE, Undefined
 from zope.tales.interfaces import ITALESExpression, ITALESFunctionNamespace
 
-Undefs = (Undefined, AttributeError, KeyError, TypeError, IndexError)
+Undefs = (Undefined, AttributeError, LookupError, TypeError)
 
 _marker = object()
 namespace_re = re.compile(r'(\w+):(.+)')

Modified: Zope3/trunk/src/zope/tales/tests/test_expressions.py
===================================================================
--- Zope3/trunk/src/zope/tales/tests/test_expressions.py	2006-04-07 11:19:19 UTC (rev 66635)
+++ Zope3/trunk/src/zope/tales/tests/test_expressions.py	2006-04-07 12:08:49 UTC (rev 66636)
@@ -19,6 +19,7 @@
 
 from zope.tales.engine import Engine
 from zope.tales.interfaces import ITALESFunctionNamespace
+from zope.tales.tales import Undefined
 from zope.interface import implements
 
 class Data(object):
@@ -30,11 +31,18 @@
 
     __str__ = __repr__
 
+class ErrorGenerator:
 
-def dict(**kw):
-    return kw
+    def __getitem__(self, name):
+        import __builtin__
+        if name == 'Undefined':
+            e = Undefined
+        else:
+            e = getattr(__builtin__, name, None)
+        if e is None:
+            e = SystemError
+        raise e('mess')
 
-
 class ExpressionTestBase(unittest.TestCase):
 
     def setUp(self):
@@ -58,6 +66,7 @@
               B = 2,
               adapterTest = at,
               dynamic = 'z',
+              ErrorGenerator = ErrorGenerator(),
               )
             )
 
@@ -86,6 +95,11 @@
         context=self.context
         self.assertEqual(expr(context), 'boot')
 
+        for e in 'Undefined', 'AttributeError', 'LookupError', 'TypeError':
+            expr = self.engine.compile('path:ErrorGenerator/%s|b|c/d/e' % e)
+            context=self.context
+            self.assertEqual(expr(context), 'boot')
+
     def testDynamic(self):
         expr = self.engine.compile('x/y/?dynamic')
         context=self.context



More information about the Zope3-Checkins mailing list