[Checkins] SVN: zope.pagetemplate/trunk/ make the PTRuntimeError exception message consistent across Python versions

Fred Drake fdrake at gmail.com
Thu Jul 8 10:22:07 EDT 2010


Log message for revision 114332:
  make the PTRuntimeError exception message consistent across Python versions

Changed:
  U   zope.pagetemplate/trunk/CHANGES.txt
  U   zope.pagetemplate/trunk/src/zope/pagetemplate/pagetemplate.py
  U   zope.pagetemplate/trunk/src/zope/pagetemplate/tests/test_basictemplate.py

-=-
Modified: zope.pagetemplate/trunk/CHANGES.txt
===================================================================
--- zope.pagetemplate/trunk/CHANGES.txt	2010-07-08 13:59:42 UTC (rev 114331)
+++ zope.pagetemplate/trunk/CHANGES.txt	2010-07-08 14:22:07 UTC (rev 114332)
@@ -2,9 +2,12 @@
 CHANGES
 =======
 
-3.5.2 (unreleased)
+3.5.2 (2010-07-08)
 ------------------
 
+- Fixed PTRuntimeError exception messages to be consistent across Python
+  versions, and compatibile with the output under Python 2.4.  (More
+  readable than the previous output under Python 2.6 as well.)
 
 3.5.1 (2010-04-30)
 ------------------

Modified: zope.pagetemplate/trunk/src/zope/pagetemplate/pagetemplate.py
===================================================================
--- zope.pagetemplate/trunk/src/zope/pagetemplate/pagetemplate.py	2010-07-08 13:59:42 UTC (rev 114331)
+++ zope.pagetemplate/trunk/src/zope/pagetemplate/pagetemplate.py	2010-07-08 14:22:07 UTC (rev 114332)
@@ -189,8 +189,9 @@
             parser.parseString(self._text)
             self._v_program, self._v_macros = parser.getCode()
         except:
+            etype, e = sys.exc_info()[:2]
             self._v_errors = ["Compilation failed",
-                              "%s: %s" % sys.exc_info()[:2]]
+                              "%s.%s: %s" % (etype.__module__, etype.__name__, e)]
         self._v_cooked = 1
 
 

Modified: zope.pagetemplate/trunk/src/zope/pagetemplate/tests/test_basictemplate.py
===================================================================
--- zope.pagetemplate/trunk/src/zope/pagetemplate/tests/test_basictemplate.py	2010-07-08 13:59:42 UTC (rev 114331)
+++ zope.pagetemplate/trunk/src/zope/pagetemplate/tests/test_basictemplate.py	2010-07-08 14:22:07 UTC (rev 114332)
@@ -16,12 +16,13 @@
 import unittest
 
 from zope.pagetemplate.tests import util
-from zope.pagetemplate.pagetemplate import PageTemplate
+import zope.pagetemplate.pagetemplate
 
+
 class BasicTemplateTests(unittest.TestCase):
 
     def setUp(self):
-        self.t = PageTemplate()
+        self.t = zope.pagetemplate.pagetemplate.PageTemplate()
 
     def test_if_in_var(self):
         # DTML test 1: if, in, and var:
@@ -59,6 +60,19 @@
         expect = util.read_output('dtml1b.html')
         util.check_xml(expect, o)
 
+    def test_pt_runtime_error(self):
+        self.t.write("<tal:block define='a string:foo'>xyz")
+        try:
+            self.t.pt_render({})
+        except zope.pagetemplate.pagetemplate.PTRuntimeError, e:
+            self.assertEquals(
+                str(e),
+                "['Compilation failed', 'zope.tal.taldefs.TALError:"
+                " TAL attributes on <tal:block> require explicit"
+                " </tal:block>, at line 1, column 1']")
+        else:
+            self.fail("expected PTRuntimeError")
+
     def test_batches_and_formatting(self):
         # DTML test 3: batches and formatting:
         pass # for unittest



More information about the checkins mailing list