[Zope3-checkins] SVN: Zope3/trunk/src/zope/tales/ Make python: expressions that do not compile raise the right exception.

Fred L. Drake, Jr. fred at zope.com
Wed Jul 7 14:34:24 EDT 2004


Log message for revision 26175:
Make python: expressions that do not compile raise the right exception.

This allows more useful error information to be presented in the UI.



-=-
Modified: Zope3/trunk/src/zope/tales/pythonexpr.py
===================================================================
--- Zope3/trunk/src/zope/tales/pythonexpr.py	2004-07-07 18:22:07 UTC (rev 26174)
+++ Zope3/trunk/src/zope/tales/pythonexpr.py	2004-07-07 18:34:24 UTC (rev 26175)
@@ -21,7 +21,10 @@
         text = ' '.join(expr.splitlines()).strip()
         self.text = text
         # The next line can legally raise SyntaxError.
-        self._code = code = compile(text, '<string>', 'eval')
+        try:
+            self._code = code = compile(text, '<string>', 'eval')
+        except SyntaxError, e:
+            raise engine.getCompilerError()(str(e))
         self._varnames = code.co_names
 
     def _bind_used_names(self, econtext, builtins):

Modified: Zope3/trunk/src/zope/tales/tests/test_expressions.py
===================================================================
--- Zope3/trunk/src/zope/tales/tests/test_expressions.py	2004-07-07 18:22:07 UTC (rev 26174)
+++ Zope3/trunk/src/zope/tales/tests/test_expressions.py	2004-07-07 18:34:24 UTC (rev 26175)
@@ -131,7 +131,11 @@
         context=self.context
         self.assertEqual(expr(context), 4)
 
+    def testPythonErrorRaisesCompilerError(self):
+        self.assertRaises(self.engine.getCompilerError(),
+                          self.engine.compile, 'python: splat.0')
 
+
 class FunctionTests(ExpressionTestBase):
 
     def setUp(self):



More information about the Zope3-Checkins mailing list