Commits

Mike Bayer committed f77fec3

- Fixed sometimes incorrect usage of
exc.__class__.__name__
in html/text error templates when using
Python 2.4 [ticket:131]

  • Participants
  • Parent commits 466cc4f

Comments (0)

Files changed (4)

+0.3.3
+- Fixed sometimes incorrect usage of 
+  exc.__class__.__name__
+  in html/text error templates when using 
+  Python 2.4 [ticket:131]
+  
 0.3.2
 - Calling a def from the top, via 
   template.get_def(...).render() now checks the 
 # the MIT License: http://www.opensource.org/licenses/mit-license.php
 
 
-__version__ = '0.3.2'
+__version__ = '0.3.3'
 

mako/exceptions.py

     
     error - the exception instance.  
     message - the exception error message as unicode
-    source - source code of the file where the error occured.  if the error occured within a compiled template,
-    this is the template source.
-    lineno - line number where the error occured.  if the error occured within a compiled template, the line number
-    is adjusted to that of the template source
-    records - a list of 8-tuples containing the original python traceback elements, plus the 
-    filename, line number, source line, and full template source for the traceline mapped back to its originating source
-    template, if any for that traceline (else the fields are None).
+    source - source code of the file where the error occured.  
+        if the error occured within a compiled template,
+        this is the template source.
+    lineno - line number where the error occured.  if the error 
+        occured within a compiled template, the line number
+        is adjusted to that of the template source
+    records - a list of 8-tuples containing the original 
+        python traceback elements, plus the 
+    filename, line number, source line, and full template source 
+        for the traceline mapped back to its originating source
+        template, if any for that traceline (else the fields are None).
     reverse_records - the list of records in reverse
-    traceback - a list of 4-tuples, in the same format as a regular python traceback, with template-corresponding 
+    traceback - a list of 4-tuples, in the same format as a regular 
+        python traceback, with template-corresponding 
     traceback records replacing the originals
     reverse_traceback - the traceback list in reverse
     
             self._has_source = True
             
         self._init_message()
-
+    
+    @property
+    def errorname(self):
+        return util.exception_name(self.error)
+        
     def _init_message(self):
         """Find a unicode representation of self.error"""
         try:
   File "${filename}", line ${lineno}, in ${function or '?'}
     ${line | unicode.strip}
 % endfor
-${str(tback.error.__class__.__name__)}: ${tback.message}
+${tback.errorname}: ${tback.message}
 """)
 
 def html_error_template():
     else:
         lines = None
 %>
-<h3>${str(tback.error.__class__.__name__)}: ${tback.message}</h3>
+<h3>${tback.errorname}: ${tback.message}</h3>
 
 % if lines:
     <div class="sample">
 
 
 py3k = getattr(sys, 'py3kwarning', False) or sys.version_info >= (3, 0)
+py24 = sys.version_info >= (2, 4) and sys.version_info < (2, 5)
 jython = sys.platform.startswith('java')
 win32 = sys.platform.startswith('win')
 
     """
     fn.__name__ = name
     return fn
-   
+ 
+if py24:
+    def exception_name(exc):
+        try:
+            return exc.__class__.__name__
+        except AttributeError:
+            return exc.__name__
+else:
+    def exception_name(exc):
+        return exc.__class__.__name__
+    
 def verify_directory(dir):
     """create and/or verify a filesystem directory."""