Added a (ugly) hack to the exceptions so that they don't warn under 2.6
authorArmin Ronacher <armin.ronacher@active-4.com>
Thu, 19 Feb 2009 19:07:13 +0000 (20:07 +0100)
committerArmin Ronacher <armin.ronacher@active-4.com>
Thu, 19 Feb 2009 19:07:13 +0000 (20:07 +0100)
--HG--
branch : trunk

jinja2/exceptions.py

index c40f7de9702f7e9a81fcc69a05388e38b0aec095..8311cf3dddf63dc5d054b245b8b0142f8a539408 100644 (file)
 class TemplateError(Exception):
     """Baseclass for all template errors."""
 
+    def __init__(self, message=None):
+        if message is not None:
+            message = unicode(message).encode('utf-8')
+        Exception.__init__(self, message)
+
+    @property
+    def message(self):
+        if self.args:
+            message = self.args[0]
+            if message is not None:
+                return message.decode('utf-8', 'replace')
+
 
 class TemplateNotFound(IOError, LookupError, TemplateError):
     """Raised if a template does not exist."""
@@ -26,14 +38,11 @@ class TemplateSyntaxError(TemplateError):
     """Raised to tell the user that there is a problem with the template."""
 
     def __init__(self, message, lineno, name=None, filename=None):
-        if not isinstance(message, unicode):
-            message = message.decode('utf-8', 'replace')
-        TemplateError.__init__(self, message.encode('utf-8'))
+        TemplateError.__init__(self, message)
         self.lineno = lineno
         self.name = name
         self.filename = filename
         self.source = None
-        self.message = message
 
     def __unicode__(self):
         location = 'line %d' % self.lineno