summaryrefslogtreecommitdiff
path: root/jinja2/exceptions.py
diff options
context:
space:
mode:
Diffstat (limited to 'jinja2/exceptions.py')
-rw-r--r--jinja2/exceptions.py43
1 files changed, 26 insertions, 17 deletions
diff --git a/jinja2/exceptions.py b/jinja2/exceptions.py
index 771f6a8..9fe698b 100644
--- a/jinja2/exceptions.py
+++ b/jinja2/exceptions.py
@@ -8,22 +8,34 @@
:copyright: (c) 2010 by the Jinja Team.
:license: BSD, see LICENSE for more details.
"""
+import sys
+import six
+from six.moves import map
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 sys.version_info[0] < 3:
+ def __init__(self, message=None):
if message is not None:
- return message.decode('utf-8', 'replace')
+ message = six.text_type(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')
+
+ else:
+ @property
+ def message(self):
+ if self.args:
+ message = self.args[0]
+ if message is not None:
+ return message
class TemplateNotFound(IOError, LookupError, TemplateError):
@@ -62,8 +74,8 @@ class TemplatesNotFound(TemplateNotFound):
def __init__(self, names=(), message=None):
if message is None:
- message = u'non of the templates given were found: ' + \
- u', '.join(map(unicode, names))
+ message = u'none of the templates given were found: ' + \
+ u', '.join(map(six.text_type, names))
TemplateNotFound.__init__(self, names and names[-1] or None, message)
self.templates = list(names)
@@ -83,12 +95,9 @@ class TemplateSyntaxError(TemplateError):
self.translated = False
def __str__(self):
- return unicode(self).encode('utf-8')
+ s = self.__unicode__()
+ return s if six.PY3 else s.encode('utf-8')
- # unicode goes after __str__ because we configured 2to3 to rename
- # __unicode__ to __str__. because the 2to3 tree is not designed to
- # remove nodes from it, we leave the above __str__ around and let
- # it override at runtime.
def __unicode__(self):
# for translated errors we only return the message
if self.translated: