From f77fec3fe9ef547a20c30fc1579c22aa7f336f19 Mon Sep 17 00:00:00 2001
From: Mike Bayer <mike_mp@zzzcomputing.com>
Date: Wed, 24 Mar 2010 15:45:55 -0400
Subject: [PATCH] - Fixed sometimes incorrect usage of   exc.__class__.__name__
   in html/text error templates when using   Python 2.4 [ticket:131]

---
 CHANGES            |  6 ++++++
 mako/__init__.py   |  2 +-
 mako/exceptions.py | 31 ++++++++++++++++++++-----------
 mako/util.py       | 13 ++++++++++++-
 4 files changed, 39 insertions(+), 13 deletions(-)

diff --git a/CHANGES b/CHANGES
index 3af9dc1..98f9e86 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,9 @@
+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 
diff --git a/mako/__init__.py b/mako/__init__.py
index 7a2f176..336d7a8 100644
--- a/mako/__init__.py
+++ b/mako/__init__.py
@@ -5,5 +5,5 @@
 # the MIT License: http://www.opensource.org/licenses/mit-license.php
 
 
-__version__ = '0.3.2'
+__version__ = '0.3.3'
 
diff --git a/mako/exceptions.py b/mako/exceptions.py
index d59d868..c0d7fd9 100644
--- a/mako/exceptions.py
+++ b/mako/exceptions.py
@@ -59,15 +59,20 @@ class RichTraceback(object):
     
     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
     
@@ -94,7 +99,11 @@ class RichTraceback(object):
             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:
@@ -229,7 +238,7 @@ Traceback (most recent call last):
   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():
@@ -280,7 +289,7 @@ 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">
diff --git a/mako/util.py b/mako/util.py
index dcac5d7..19afc0d 100644
--- a/mako/util.py
+++ b/mako/util.py
@@ -8,6 +8,7 @@ import sys
 
 
 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')
 
@@ -42,7 +43,17 @@ def function_named(fn, name):
     """
     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."""
     
-- 
GitLab