Added first version of IR importer/exporter
[libfirm] / scripts / jinja2 / exceptions.py
1 # -*- coding: utf-8 -*-
2 """
3     jinja2.exceptions
4     ~~~~~~~~~~~~~~~~~
5
6     Jinja exceptions.
7
8     :copyright: 2008 by Armin Ronacher.
9     :license: BSD, see LICENSE for more details.
10 """
11
12
13 class TemplateError(Exception):
14     """Baseclass for all template errors."""
15
16
17 class TemplateNotFound(IOError, LookupError, TemplateError):
18     """Raised if a template does not exist."""
19
20     def __init__(self, name):
21         IOError.__init__(self, name)
22         self.name = name
23
24
25 class TemplateSyntaxError(TemplateError):
26     """Raised to tell the user that there is a problem with the template."""
27
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'))
32         self.lineno = lineno
33         self.name = name
34         self.filename = filename
35         self.source = None
36         self.message = message
37
38     def __unicode__(self):
39         location = 'line %d' % self.lineno
40         name = self.filename or self.name
41         if name:
42             location = 'File "%s", %s' % (name, location)
43         lines = [self.message, '  ' + location]
44
45         # if the source is set, add the line to the output
46         if self.source is not None:
47             try:
48                 line = self.source.splitlines()[self.lineno - 1]
49             except IndexError:
50                 line = None
51             if line:
52                 lines.append('    ' + line.strip())
53
54         return u'\n'.join(lines)
55
56     def __str__(self):
57         return unicode(self).encode('utf-8')
58
59
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.
65     """
66
67
68 class TemplateRuntimeError(TemplateError):
69     """A generic runtime error in the template engine.  Under some situations
70     Jinja may raise this exception.
71     """
72
73
74 class UndefinedError(TemplateRuntimeError):
75     """Raised if a template tries to operate on :class:`Undefined`."""
76
77
78 class SecurityError(TemplateRuntimeError):
79     """Raised if a template tries to do something insecure if the
80     sandbox is enabled.
81     """
82
83
84 class FilterArgumentError(TemplateRuntimeError):
85     """This error is raised if a filter was called with inappropriate
86     arguments
87     """