mirror of
https://github.com/rembo10/headphones.git
synced 2026-07-22 00:44:00 +01:00
Updated mako libs to 0.7.2
This commit is contained in:
+96
-41
@@ -1,5 +1,5 @@
|
||||
# mako/exceptions.py
|
||||
# Copyright (C) 2006-2011 the Mako authors and contributors <see AUTHORS file>
|
||||
# Copyright (C) 2006-2012 the Mako authors and contributors <see AUTHORS file>
|
||||
#
|
||||
# This module is part of Mako and is released under
|
||||
# the MIT License: http://www.opensource.org/licenses/mit-license.php
|
||||
@@ -20,19 +20,21 @@ def _format_filepos(lineno, pos, filename):
|
||||
return " at line: %d char: %d" % (lineno, pos)
|
||||
else:
|
||||
return " in file '%s' at line: %d char: %d" % (filename, lineno, pos)
|
||||
|
||||
|
||||
|
||||
|
||||
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
|
||||
@@ -40,47 +42,50 @@ class SyntaxException(MakoException):
|
||||
|
||||
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):
|
||||
"""Pulls the current exception from the sys traceback and extracts
|
||||
"""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
|
||||
|
||||
if error is None or traceback is None:
|
||||
t, value, tback = sys.exc_info()
|
||||
|
||||
|
||||
if error is None:
|
||||
error = value or t
|
||||
|
||||
|
||||
if traceback is None:
|
||||
traceback = tback
|
||||
|
||||
|
||||
self.error = error
|
||||
self.records = self._init(traceback)
|
||||
|
||||
|
||||
if isinstance(self.error, (CompileException, SyntaxException)):
|
||||
import mako.template
|
||||
self.source = self.error.source
|
||||
self.lineno = self.error.lineno
|
||||
self._has_source = True
|
||||
|
||||
|
||||
self._init_message()
|
||||
|
||||
|
||||
@property
|
||||
def errorname(self):
|
||||
return util.exception_name(self.error)
|
||||
|
||||
|
||||
def _init_message(self):
|
||||
"""Find a unicode representation of self.error"""
|
||||
try:
|
||||
@@ -101,25 +106,25 @@ class RichTraceback(object):
|
||||
yield (rec[4], rec[5], rec[2], rec[6])
|
||||
else:
|
||||
yield tuple(rec[0:4])
|
||||
|
||||
|
||||
@property
|
||||
def traceback(self):
|
||||
"""return a list of 4-tuple traceback records (i.e. normal python
|
||||
"""Return a list of 4-tuple traceback records (i.e. normal python
|
||||
format) with template-corresponding lines remapped to the originating
|
||||
template.
|
||||
|
||||
|
||||
"""
|
||||
return list(self._get_reformatted_records(self.records))
|
||||
|
||||
|
||||
@property
|
||||
def reverse_records(self):
|
||||
return reversed(self.records)
|
||||
|
||||
|
||||
@property
|
||||
def reverse_traceback(self):
|
||||
"""return the same data as traceback, except in reverse order.
|
||||
"""Return the same data as traceback, except in reverse order.
|
||||
"""
|
||||
|
||||
|
||||
return list(self._get_reformatted_records(self.reverse_records))
|
||||
|
||||
def _init(self, trcback):
|
||||
@@ -156,7 +161,7 @@ class RichTraceback(object):
|
||||
line = line.decode(encoding)
|
||||
else:
|
||||
line = line.decode('ascii', 'replace')
|
||||
new_trcback.append((filename, lineno, function, line,
|
||||
new_trcback.append((filename, lineno, function, line,
|
||||
None, None, None, None))
|
||||
continue
|
||||
|
||||
@@ -177,8 +182,8 @@ class RichTraceback(object):
|
||||
template_line = template_lines[template_ln - 1]
|
||||
else:
|
||||
template_line = None
|
||||
new_trcback.append((filename, lineno, function,
|
||||
line, template_filename, template_ln,
|
||||
new_trcback.append((filename, lineno, function,
|
||||
line, template_filename, template_ln,
|
||||
template_line, template_source))
|
||||
if not self.source:
|
||||
for l in range(len(new_trcback)-1, 0, -1):
|
||||
@@ -202,13 +207,13 @@ class RichTraceback(object):
|
||||
self.lineno = new_trcback[-1][1]
|
||||
return new_trcback
|
||||
|
||||
|
||||
|
||||
def text_error_template(lookup=None):
|
||||
"""Provides a template that renders a stack trace in a similar format to
|
||||
the Python interpreter, substituting source template filenames, line
|
||||
numbers and code for that of the originating source template, as
|
||||
applicable.
|
||||
|
||||
|
||||
"""
|
||||
import mako.template
|
||||
return mako.template.Template(r"""
|
||||
@@ -227,22 +232,33 @@ Traceback (most recent call last):
|
||||
${tback.errorname}: ${tback.message}
|
||||
""")
|
||||
|
||||
|
||||
try:
|
||||
from mako.ext.pygmentplugin import syntax_highlight,\
|
||||
pygments_html_formatter
|
||||
except ImportError:
|
||||
from mako.filters import html_escape
|
||||
pygments_html_formatter = None
|
||||
def syntax_highlight(filename='', language=None):
|
||||
return html_escape
|
||||
|
||||
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
|
||||
filenames, line numbers and code for that of the originating source
|
||||
template, as applicable.
|
||||
|
||||
The template's default encoding_errors value is 'htmlentityreplace'. the
|
||||
template has two options. With the full option disabled, only a section of
|
||||
an HTML document is returned. with the css option disabled, the default
|
||||
The template's default ``encoding_errors`` value is ``'htmlentityreplace'``. The
|
||||
template has two options. With the ``full`` option disabled, only a section of
|
||||
an HTML document is returned. With the ``css`` option disabled, the default
|
||||
stylesheet won't be included.
|
||||
|
||||
|
||||
"""
|
||||
import mako.template
|
||||
return mako.template.Template(r"""
|
||||
<%!
|
||||
from mako.exceptions import RichTraceback
|
||||
from mako.exceptions import RichTraceback, syntax_highlight,\
|
||||
pygments_html_formatter
|
||||
%>
|
||||
<%page args="full=True, css=True, error=None, traceback=None"/>
|
||||
% if full:
|
||||
@@ -256,10 +272,29 @@ def html_error_template():
|
||||
.stacktrace { margin:5px 5px 5px 5px; }
|
||||
.highlight { padding:0px 10px 0px 10px; background-color:#9F9FDF; }
|
||||
.nonhighlight { padding:0px; background-color:#DFDFDF; }
|
||||
.sample { padding:10px; margin:10px 10px 10px 10px; font-family:monospace; }
|
||||
.sample { padding:10px; margin:10px 10px 10px 10px;
|
||||
font-family:monospace; }
|
||||
.sampleline { padding:0px 10px 0px 10px; }
|
||||
.sourceline { margin:5px 5px 10px 5px; font-family:monospace;}
|
||||
.location { font-size:80%; }
|
||||
.highlight { white-space:pre; }
|
||||
.sampleline { white-space:pre; }
|
||||
|
||||
% if pygments_html_formatter:
|
||||
${pygments_html_formatter.get_style_defs()}
|
||||
.linenos { min-width: 2.5em; text-align: right; }
|
||||
pre { margin: 0; }
|
||||
.syntax-highlighted { padding: 0 10px; }
|
||||
.syntax-highlightedtable { border-spacing: 1px; }
|
||||
.nonhighlight { border-top: 1px solid #DFDFDF;
|
||||
border-bottom: 1px solid #DFDFDF; }
|
||||
.stacktrace .nonhighlight { margin: 5px 15px 10px; }
|
||||
.sourceline { margin: 0 0; font-family:monospace; }
|
||||
.code { background-color: #F8F8F8; width: 100%; }
|
||||
.error .code { background-color: #FFBDBD; }
|
||||
.error .syntax-highlighted { background-color: #FFBDBD; }
|
||||
% endif
|
||||
|
||||
</style>
|
||||
% endif
|
||||
% if full:
|
||||
@@ -277,16 +312,29 @@ def html_error_template():
|
||||
else:
|
||||
lines = None
|
||||
%>
|
||||
<h3>${tback.errorname}: ${tback.message}</h3>
|
||||
<h3>${tback.errorname}: ${tback.message|h}</h3>
|
||||
|
||||
% if lines:
|
||||
<div class="sample">
|
||||
<div class="nonhighlight">
|
||||
% for index in range(max(0, line-4),min(len(lines), line+5)):
|
||||
<%
|
||||
if pygments_html_formatter:
|
||||
pygments_html_formatter.linenostart = index + 1
|
||||
%>
|
||||
% if index + 1 == line:
|
||||
<div class="highlight">${index + 1} ${lines[index] | h}</div>
|
||||
<%
|
||||
if pygments_html_formatter:
|
||||
old_cssclass = pygments_html_formatter.cssclass
|
||||
pygments_html_formatter.cssclass = 'error ' + old_cssclass
|
||||
%>
|
||||
${lines[index] | syntax_highlight(language='mako')}
|
||||
<%
|
||||
if pygments_html_formatter:
|
||||
pygments_html_formatter.cssclass = old_cssclass
|
||||
%>
|
||||
% else:
|
||||
<div class="sampleline">${index + 1} ${lines[index] | h}</div>
|
||||
${lines[index] | syntax_highlight(language='mako')}
|
||||
% endif
|
||||
% endfor
|
||||
</div>
|
||||
@@ -296,7 +344,13 @@ def html_error_template():
|
||||
<div class="stacktrace">
|
||||
% for (filename, lineno, function, line) in tback.reverse_traceback:
|
||||
<div class="location">${filename}, line ${lineno}:</div>
|
||||
<div class="sourceline">${line | h}</div>
|
||||
<div class="nonhighlight">
|
||||
<%
|
||||
if pygments_html_formatter:
|
||||
pygments_html_formatter.linenostart = lineno
|
||||
%>
|
||||
<div class="sourceline">${line | syntax_highlight(filename)}</div>
|
||||
</div>
|
||||
% endfor
|
||||
</div>
|
||||
|
||||
@@ -304,4 +358,5 @@ def html_error_template():
|
||||
</body>
|
||||
</html>
|
||||
% endif
|
||||
""", output_encoding=sys.getdefaultencoding(), encoding_errors='htmlentityreplace')
|
||||
""", output_encoding=sys.getdefaultencoding(),
|
||||
encoding_errors='htmlentityreplace')
|
||||
|
||||
Reference in New Issue
Block a user