diff --git a/CHANGES b/CHANGES index 3af9dc1359e397861698f4ec839ef1c45c8d97cc..98f9e8604c6394538c00fcf8b5d43b88317acb7b 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 7a2f176b16665013602930a9a74116be62b220aa..336d7a8b4f7187dc51e08407b56ea8edba8851a3 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 d59d8683966aaa84daf4d0590427e824c0bbee3c..c0d7fd9587bfdf2591e57740327d4d081cdb09c7 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 dcac5d757e3d98a0a9ba4ff6318f0e2762d29dad..19afc0d66be3239c7be686fbc43c606bfc421e66 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."""