[Zope3-checkins] SVN: Zope3/branches/jim-adapter/src/zope/tales/
The tales path expression "|" now catches LookupError, rather than
Jim Fulton
jim at zope.com
Mon Apr 3 19:00:47 EDT 2006
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/branches/jim-adapter/src/zope/tales/expressions.py
U Zope3/branches/jim-adapter/src/zope/tales/tests/test_expressions.py
-=-
Modified: Zope3/branches/jim-adapter/src/zope/tales/expressions.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/tales/expressions.py 2006-04-03 20:47:59 UTC (rev 66357)
+++ Zope3/branches/jim-adapter/src/zope/tales/expressions.py 2006-04-03 23:00:46 UTC (rev 66358)
@@ -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/branches/jim-adapter/src/zope/tales/tests/test_expressions.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/tales/tests/test_expressions.py 2006-04-03 20:47:59 UTC (rev 66357)
+++ Zope3/branches/jim-adapter/src/zope/tales/tests/test_expressions.py 2006-04-03 23:00:46 UTC (rev 66358)
@@ -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