1 # -*- coding: utf-8 -*-
8 :copyright: 2008 by Armin Ronacher.
9 :license: BSD, see LICENSE for more details.
13 class TemplateError(Exception):
14 """Baseclass for all template errors."""
17 class TemplateNotFound(IOError, LookupError, TemplateError):
18 """Raised if a template does not exist."""
20 def __init__(self, name):
21 IOError.__init__(self, name)
25 class TemplateSyntaxError(TemplateError):
26 """Raised to tell the user that there is a problem with the template."""
28 def __init__(self, message, lineno, name=None, filename=None):
29 if not isinstance(message, unicode):
30 message = message.decode('utf-8', 'replace')
31 TemplateError.__init__(self, message.encode('utf-8'))
34 self.filename = filename
36 self.message = message
38 def __unicode__(self):
39 location = 'line %d' % self.lineno
40 name = self.filename or self.name
42 location = 'File "%s", %s' % (name, location)
43 lines = [self.message, ' ' + location]
45 # if the source is set, add the line to the output
46 if self.source is not None:
48 line = self.source.splitlines()[self.lineno - 1]
52 lines.append(' ' + line.strip())
54 return u'\n'.join(lines)
57 return unicode(self).encode('utf-8')
60 class TemplateAssertionError(TemplateSyntaxError):
61 """Like a template syntax error, but covers cases where something in the
62 template caused an error at compile time that wasn't necessarily caused
63 by a syntax error. However it's a direct subclass of
64 :exc:`TemplateSyntaxError` and has the same attributes.
68 class TemplateRuntimeError(TemplateError):
69 """A generic runtime error in the template engine. Under some situations
70 Jinja may raise this exception.
74 class UndefinedError(TemplateRuntimeError):
75 """Raised if a template tries to operate on :class:`Undefined`."""
78 class SecurityError(TemplateRuntimeError):
79 """Raised if a template tries to do something insecure if the
84 class FilterArgumentError(TemplateRuntimeError):
85 """This error is raised if a filter was called with inappropriate