Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Unified Diff: third_party/jinja2/exceptions.py

Issue 23506004: Update Jinja2 (Python template library) to 2.7.1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/jinja2/environment.py ('k') | third_party/jinja2/ext.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/jinja2/exceptions.py
diff --git a/third_party/jinja2/exceptions.py b/third_party/jinja2/exceptions.py
index 771f6a8d7a763e9bf2201ff9511dc25611ca7456..c9df6dc7c28a11aa4a9ec8c18eacaf32affeca31 100644
--- a/third_party/jinja2/exceptions.py
+++ b/third_party/jinja2/exceptions.py
@@ -8,24 +8,40 @@
:copyright: (c) 2010 by the Jinja Team.
:license: BSD, see LICENSE for more details.
"""
+from jinja2._compat import imap, text_type, PY2, implements_to_string
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 PY2:
+ def __init__(self, message=None):
if message is not None:
- return message.decode('utf-8', 'replace')
-
-
+ message = 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')
+
+ def __unicode__(self):
+ return self.message or u''
+ else:
+ def __init__(self, message=None):
+ Exception.__init__(self, message)
+
+ @property
+ def message(self):
+ if self.args:
+ message = self.args[0]
+ if message is not None:
+ return message
+
+
+@implements_to_string
class TemplateNotFound(IOError, LookupError, TemplateError):
"""Raised if a template does not exist."""
@@ -42,13 +58,6 @@ class TemplateNotFound(IOError, LookupError, TemplateError):
self.templates = [name]
def __str__(self):
- return self.message.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):
return self.message
@@ -62,12 +71,13 @@ 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(imap(text_type, names))
TemplateNotFound.__init__(self, names and names[-1] or None, message)
self.templates = list(names)
+@implements_to_string
class TemplateSyntaxError(TemplateError):
"""Raised to tell the user that there is a problem with the template."""
@@ -83,13 +93,6 @@ class TemplateSyntaxError(TemplateError):
self.translated = False
def __str__(self):
- return unicode(self).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:
return self.message
« no previous file with comments | « third_party/jinja2/environment.py ('k') | third_party/jinja2/ext.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698