Skip to content
Myr

exceptions.py

This file

Path

jinja2/exceptions.py

143 lines · 4.4 KiB · Python

Last changed by

Down to 7 failures for Python 3. We're onto something.Armin Ronacherbefore adoption0d242be

History of this file

Take it

The walk stopped after 200 commits: lines older than 8f45555 point at it.

Nearly complete core django template code coverage.Armin Ronacherbefore adoption8f45555

lines 1–7why, one step back
1# -*- coding: utf-8 -*-
2"""3 jinja2.exceptions4 ~~~~~~~~~~~~~~~~~56 Jinja exceptions.7

It's a new yearArmin Ronacherbefore adoption55494e4

line 8why, one step back
8 :copyright: (c) 2010 by the Jinja Team.

Nearly complete core django template code coverage.Armin Ronacherbefore adoption8f45555

lines 9–15why, one step back
9 :license: BSD, see LICENSE for more details.
10"""111213class TemplateError(Exception):14 """Baseclass for all template errors."""15

Added a (ugly) hack to the exceptions so that they don't warn under 2.6Armin Ronacherbefore adoption1d02108

lines 16–19why, one step back
16 def __init__(self, message=None):
17 if message is not None:18 message = unicode(message).encode('utf-8')19 Exception.__init__(self, message)

Nearly complete core django template code coverage.Armin Ronacherbefore adoption8f45555

line 20why, one step back
20

Added a (ugly) hack to the exceptions so that they don't warn under 2.6Armin Ronacherbefore adoption1d02108

lines 21–28why, one step back
21 @property
22 def message(self):23 if self.args:24 message = self.args[0]25 if message is not None:26 return message.decode('utf-8', 'replace')2728

Nearly complete core django template code coverage.Armin Ronacherbefore adoption8f45555

lines 29–31why, one step back
29class TemplateNotFound(IOError, LookupError, TemplateError):
30 """Raised if a template does not exist."""31

include tags are now able to select between multiple templatesArmin Ronacherbefore adoption31bbd9e

lines 32–40why, one step back
32 # looks weird, but removes the warning descriptor that just
33 # bogusly warns us about message being deprecated34 message = None3536 def __init__(self, name, message=None):37 IOError.__init__(self)38 if message is None:39 message = name40 self.message = message

Nearly complete core django template code coverage.Armin Ronacherbefore adoption8f45555

line 41why, one step back
41 self.name = name

include tags are now able to select between multiple templatesArmin Ronacherbefore adoption31bbd9e

lines 42–46why, one step back
42 self.templates = [name]
4344 def __str__(self):45 return self.message.encode('utf-8')46

Added comment to why __unicode__ goes after __str__.Armin Ronacherbefore adoptionacbd408

lines 47–50why, one step back
47 # unicode goes after __str__ because we configured 2to3 to rename
48 # __unicode__ to __str__. because the 2to3 tree is not designed to49 # remove nodes from it, we leave the above __str__ around and let50 # it override at runtime.

Approaching python3 compatibilityArmin Ronacherbefore adoption790b8a8

lines 51–52why, one step back
51 def __unicode__(self):
52 return self.message

include tags are now able to select between multiple templatesArmin Ronacherbefore adoption31bbd9e

line 53why, one step back
53

Approaching python3 compatibilityArmin Ronacherbefore adoption790b8a8

line 54why, one step back
54

include tags are now able to select between multiple templatesArmin Ronacherbefore adoption31bbd9e

lines 55–65why, one step back
55class TemplatesNotFound(TemplateNotFound):
56 """Like :class:`TemplateNotFound` but raised if multiple templates57 are selected. This is a subclass of :class:`TemplateNotFound`58 exception, so just catching the base exception will catch both.5960 .. versionadded:: 2.261 """6263 def __init__(self, names=(), message=None):64 if message is None:65 message = u'non of the templates given were found: ' + \

Fixed the choice include tests.Armin Ronacherbefore adoption7e40df0

line 66why, one step back
66 u', '.join(map(unicode, names))

include tags are now able to select between multiple templatesArmin Ronacherbefore adoption31bbd9e

lines 67–68why, one step back
67 TemplateNotFound.__init__(self, names and names[-1] or None, message)
68 self.templates = list(names)

Nearly complete core django template code coverage.Armin Ronacherbefore adoption8f45555

lines 69–74why, one step back
69
7071class TemplateSyntaxError(TemplateError):72 """Raised to tell the user that there is a problem with the template."""7374 def __init__(self, message, lineno, name=None, filename=None):

Added a (ugly) hack to the exceptions so that they don't warn under 2.6Armin Ronacherbefore adoption1d02108

line 75why, one step back
75 TemplateError.__init__(self, message)

Nearly complete core django template code coverage.Armin Ronacherbefore adoption8f45555

lines 76–78why, one step back
76 self.lineno = lineno
77 self.name = name78 self.filename = filename

Various cleanups and added custom cycler.Armin Ronacherbefore adoptionccae055

lines 79–80why, one step back
79 self.source = None
80

Improved Jinja's debugging support by introducing "@internalcode" which marks code objects that are skipped on tracebacks. Also template errors are now translated as well to help the pylons debugger.Armin Ronacherbefore adoptiond416a97

lines 81–84why, one step back
81 # this is set to True if the debug.translate_syntax_error
82 # function translated the syntax error into a new traceback83 self.translated = False84

Approaching python3 compatibilityArmin Ronacherbefore adoption790b8a8

lines 85–87why, one step back
85 def __str__(self):
86 return unicode(self).encode('utf-8')87

Added comment to why __unicode__ goes after __str__.Armin Ronacherbefore adoptionacbd408

lines 88–91why, one step back
88 # unicode goes after __str__ because we configured 2to3 to rename
89 # __unicode__ to __str__. because the 2to3 tree is not designed to90 # remove nodes from it, we leave the above __str__ around and let91 # it override at runtime.

Various cleanups and added custom cycler.Armin Ronacherbefore adoptionccae055

line 92why, one step back
92 def __unicode__(self):

Improved Jinja's debugging support by introducing "@internalcode" which marks code objects that are skipped on tracebacks. Also template errors are now translated as well to help the pylons debugger.Armin Ronacherbefore adoptiond416a97

lines 93–94why, one step back
93 # for translated errors we only return the message
94 if self.translated:

Down to 7 failures for Python 3. We're onto something.Armin Ronacherbefore adoption0d242be

line 95why, one step back
95 return self.message

Improved Jinja's debugging support by introducing "@internalcode" which marks code objects that are skipped on tracebacks. Also template errors are now translated as well to help the pylons debugger.Armin Ronacherbefore adoptiond416a97

lines 96–97why, one step back
96
97 # otherwise attach some stuff

Various cleanups and added custom cycler.Armin Ronacherbefore adoptionccae055

lines 98–113why, one step back
98 location = 'line %d' % self.lineno
99 name = self.filename or self.name100 if name:101 location = 'File "%s", %s' % (name, location)102 lines = [self.message, ' ' + location]103104 # if the source is set, add the line to the output105 if self.source is not None:106 try:107 line = self.source.splitlines()[self.lineno - 1]108 except IndexError:109 line = None110 if line:111 lines.append(' ' + line.strip())112113 return u'\n'.join(lines)

Nearly complete core django template code coverage.Armin Ronacherbefore adoption8f45555

lines 114–143why, one step back
114
115116class TemplateAssertionError(TemplateSyntaxError):117 """Like a template syntax error, but covers cases where something in the118 template caused an error at compile time that wasn't necessarily caused119 by a syntax error. However it's a direct subclass of120 :exc:`TemplateSyntaxError` and has the same attributes.121 """122123124class TemplateRuntimeError(TemplateError):125 """A generic runtime error in the template engine. Under some situations126 Jinja may raise this exception.127 """128129130class UndefinedError(TemplateRuntimeError):131 """Raised if a template tries to operate on :class:`Undefined`."""132133134class SecurityError(TemplateRuntimeError):135 """Raised if a template tries to do something insecure if the136 sandbox is enabled.137 """138139140class FilterArgumentError(TemplateRuntimeError):141 """This error is raised if a filter was called with inappropriate142 arguments143 """