From acbd408b9955a6e13c6330a209098e24fb8fed5b Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Wed, 10 Feb 2010 00:07:43 +0100 Subject: [PATCH] Added comment to why __unicode__ goes after __str__. --HG-- branch : trunk --- jinja2/environment.py | 4 ++++ jinja2/exceptions.py | 8 ++++++++ jinja2/runtime.py | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/jinja2/environment.py b/jinja2/environment.py index 965b058..fe7ed02 100644 --- a/jinja2/environment.py +++ b/jinja2/environment.py @@ -814,6 +814,10 @@ class TemplateModule(object): 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): return concat(self._body_stream) diff --git a/jinja2/exceptions.py b/jinja2/exceptions.py index 4df8324..69a877b 100644 --- a/jinja2/exceptions.py +++ b/jinja2/exceptions.py @@ -44,6 +44,10 @@ class TemplateNotFound(IOError, LookupError, TemplateError): 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 @@ -81,6 +85,10 @@ class TemplateSyntaxError(TemplateError): 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: diff --git a/jinja2/runtime.py b/jinja2/runtime.py index ae394e3..be5b09a 100644 --- a/jinja2/runtime.py +++ b/jinja2/runtime.py @@ -454,6 +454,10 @@ class Undefined(object): 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): return u'' -- 2.26.2