From 1d021082f61dbad8ba64181b743cd29da514dfff Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Thu, 19 Feb 2009 20:07:13 +0100 Subject: [PATCH] Added a (ugly) hack to the exceptions so that they don't warn under 2.6 --HG-- branch : trunk --- jinja2/exceptions.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/jinja2/exceptions.py b/jinja2/exceptions.py index c40f7de..8311cf3 100644 --- a/jinja2/exceptions.py +++ b/jinja2/exceptions.py @@ -13,6 +13,18 @@ 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 -- 2.26.2