Raised to tell the user that there is a problem with the template.
| 79 | |
| 80 | @implements_to_string |
| 81 | class TemplateSyntaxError(TemplateError): |
| 82 | """Raised to tell the user that there is a problem with the template.""" |
| 83 | |
| 84 | def __init__(self, message, lineno, name=None, filename=None): |
| 85 | TemplateError.__init__(self, message) |
| 86 | self.lineno = lineno |
| 87 | self.name = name |
| 88 | self.filename = filename |
| 89 | self.source = None |
| 90 | |
| 91 | # this is set to True if the debug.translate_syntax_error |
| 92 | # function translated the syntax error into a new traceback |
| 93 | self.translated = False |
| 94 | |
| 95 | def __str__(self): |
| 96 | # for translated errors we only return the message |
| 97 | if self.translated: |
| 98 | return self.message |
| 99 | |
| 100 | # otherwise attach some stuff |
| 101 | location = 'line %d' % self.lineno |
| 102 | name = self.filename or self.name |
| 103 | if name: |
| 104 | location = 'File "%s", %s' % (name, location) |
| 105 | lines = [self.message, ' ' + location] |
| 106 | |
| 107 | # if the source is set, add the line to the output |
| 108 | if self.source is not None: |
| 109 | try: |
| 110 | line = self.source.splitlines()[self.lineno - 1] |
| 111 | except IndexError: |
| 112 | line = None |
| 113 | if line: |
| 114 | lines.append(' ' + line.strip()) |
| 115 | |
| 116 | return u'\n'.join(lines) |
| 117 | |
| 118 | |
| 119 | class TemplateAssertionError(TemplateSyntaxError): |
no outgoing calls
no test coverage detected
searching dependent graphs…