aboutsummaryrefslogtreecommitdiffstats
path: root/mako/exceptions.py
diff options
context:
space:
mode:
Diffstat (limited to 'mako/exceptions.py')
-rw-r--r--mako/exceptions.py45
1 files changed, 33 insertions, 12 deletions
diff --git a/mako/exceptions.py b/mako/exceptions.py
index c531f21..84d2297 100644
--- a/mako/exceptions.py
+++ b/mako/exceptions.py
@@ -10,12 +10,15 @@ import traceback
import sys
from mako import util, compat
+
class MakoException(Exception):
pass
+
class RuntimeException(MakoException):
pass
+
def _format_filepos(lineno, pos, filename):
if filename is None:
return " at line: %d char: %d" % (lineno, pos)
@@ -24,42 +27,56 @@ def _format_filepos(lineno, pos, filename):
class CompileException(MakoException):
+
def __init__(self, message, source, lineno, pos, filename):
- MakoException.__init__(self,
- message + _format_filepos(lineno, pos, filename))
+ MakoException.__init__(
+ self,
+ message + _format_filepos(lineno, pos, filename))
self.lineno = lineno
self.pos = pos
self.filename = filename
self.source = source
+
class SyntaxException(MakoException):
+
def __init__(self, message, source, lineno, pos, filename):
- MakoException.__init__(self,
- message + _format_filepos(lineno, pos, filename))
+ MakoException.__init__(
+ self,
+ message + _format_filepos(lineno, pos, filename))
self.lineno = lineno
self.pos = pos
self.filename = filename
self.source = source
+
class UnsupportedError(MakoException):
+
"""raised when a retired feature is used."""
+
class NameConflictError(MakoException):
+
"""raised when a reserved word is used inappropriately"""
+
class TemplateLookupException(MakoException):
pass
+
class TopLevelLookupException(TemplateLookupException):
pass
+
class RichTraceback(object):
+
"""Pull the current exception from the ``sys`` traceback and extracts
Mako-specific template information.
See the usage examples in :ref:`handling_exceptions`.
"""
+
def __init__(self, error=None, traceback=None):
self.source, self.lineno = "", 0
@@ -162,18 +179,18 @@ class RichTraceback(object):
else:
line = line.decode('ascii', 'replace')
new_trcback.append((filename, lineno, function, line,
- None, None, None, None))
+ None, None, None, None))
continue
template_ln = 1
source_map = mako.template.ModuleInfo.\
- get_module_source_metadata(
- module_source, full_line_map=True)
+ get_module_source_metadata(
+ module_source, full_line_map=True)
line_map = source_map['full_line_map']
- template_lines = [line for line in
- template_source.split("\n")]
+ template_lines = [line_ for line_ in
+ template_source.split("\n")]
mods[filename] = (line_map, template_lines)
template_ln = line_map[lineno - 1]
@@ -235,16 +252,19 @@ ${tback.errorname}: ${tback.message}
def _install_pygments():
global syntax_highlight, pygments_html_formatter
- from mako.ext.pygmentplugin import syntax_highlight,\
- pygments_html_formatter
+ from mako.ext.pygmentplugin import syntax_highlight # noqa
+ from mako.ext.pygmentplugin import pygments_html_formatter # noqa
+
def _install_fallback():
global syntax_highlight, pygments_html_formatter
from mako.filters import html_escape
pygments_html_formatter = None
+
def syntax_highlight(filename='', language=None):
return html_escape
+
def _install_highlighting():
try:
_install_pygments()
@@ -252,6 +272,7 @@ def _install_highlighting():
_install_fallback()
_install_highlighting()
+
def html_error_template():
"""Provides a template that renders a stack trace in an HTML format,
providing an excerpt of code as well as substituting source template
@@ -370,4 +391,4 @@ def html_error_template():
</html>
% endif
""", output_encoding=sys.getdefaultencoding(),
- encoding_errors='htmlentityreplace')
+ encoding_errors='htmlentityreplace')