Skip to content
Myr

Python 3 exceptions can handle unicode messages

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Alex Morega · committed by Alex Morega · parent a1f2ee7 · Browse files · 1 file+20 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+20 added−10 removed

  • other:+20 added−10 removed

1 file+20 added−10 removed

modified:jinja2/exceptions.py+20 added-10 removed
6 unmodified lines
78 :copyright: (c) 2010 by the Jinja Team.9 :license: BSD, see LICENSE for more details.10"""11import sys12import six13from six.moves import map141516class TemplateError(Exception):17 """Baseclass for all template errors."""1818 def __init__(self, message=None):19 if message is not None:20 message = six.text_type(message).encode('utf-8')21 Exception.__init__(self, message)2223 @property24 def message(self):25 if self.args:26 message = self.args[0]19 if sys.version_info[0] < 3:20 def __init__(self, message=None):21 if message is not None:28 return message.decode('utf-8', 'replace')22 message = six.text_type(message).encode('utf-8')23 Exception.__init__(self, message)2425 @property26 def message(self):27 if self.args:28 message = self.args[0]29 if message is not None:30 return message.decode('utf-8', 'replace')3132 else:33 @property34 def message(self):35 if self.args:36 message = self.args[0]37 if message is not None:38 return message394041class TemplateNotFound(IOError, LookupError, TemplateError):42 """Raised if a template does not exist."""4344 # looks weird, but removes the warning descriptor that just
108 unmodified lines