diff options
author | ianb <devnull@localhost> | 2005-11-06 23:34:59 +0000 |
---|---|---|
committer | ianb <devnull@localhost> | 2005-11-06 23:34:59 +0000 |
commit | b5ffe641cff3f96bd18384ea3bb123c187400c6d (patch) | |
tree | 555365b214cd91fdd647c983723f794664fdb8fd /paste/exceptions | |
parent | f799fd0469480a101cb620646861a2a5154aa6ee (diff) | |
download | paste-b5ffe641cff3f96bd18384ea3bb123c187400c6d.tar.gz |
Improved UI of the error catcher in several ways
Diffstat (limited to 'paste/exceptions')
-rw-r--r-- | paste/exceptions/formatter.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/paste/exceptions/formatter.py b/paste/exceptions/formatter.py index d50de94..3692015 100644 --- a/paste/exceptions/formatter.py +++ b/paste/exceptions/formatter.py @@ -248,8 +248,8 @@ class HTMLFormatter(TextFormatter): filename, modname, lineno, name) return 'File %r, line %s in <tt>%s</tt>' % (filename, lineno, name) def format_long_source(self, source, long_source): - q_long_source = str2html(long_source, False, 4) - q_source = str2html(source, True, 0) + q_long_source = str2html(long_source, False, 4, True) + q_source = str2html(source, True, 0, False) return ('<code style="display: none" class="source" source-type="long"><a class="switch_source" onclick="return switch_source(this, \'long\')" href="#"><< </a>%s</code>' '<code class="source" source-type="short"><a onclick="return switch_source(this, \'short\')" class="switch_source" href="#">>> </a>%s</code>' % (q_long_source, @@ -458,17 +458,21 @@ whitespace_re = re.compile(r' +') pre_re = re.compile(r'</?pre.*?>') error_re = re.compile(r'<h3>ERROR: .*?</h3>') -def str2html(src, strip=False, indent_subsequent=0): +def str2html(src, strip=False, indent_subsequent=0, + highlight_inner=False): """ Convert a string to HTML. Try to be really safe about it, returning a quoted version of the string if nothing else works. """ try: - return _str2html(src, strip=strip, indent_subsequent=indent_subsequent) + return _str2html(src, strip=strip, + indent_subsequent=indent_subsequent, + highlight_inner=highlight_inner) except: return html_quote(src) -def _str2html(src, strip=False, indent_subsequent=0): +def _str2html(src, strip=False, indent_subsequent=0, + highlight_inner=False): if strip: src = src.strip() orig_src = src @@ -486,7 +490,7 @@ def _str2html(src, strip=False, indent_subsequent=0): indent = ' '*indent_subsequent for i in range(1, len(lines)): lines[i] = indent+lines[i] - if i == len(lines)/2: + if highlight_inner and i == len(lines)/2: lines[i] = '<span class="source-highlight">%s</span>' % lines[i] src = '<br>\n'.join(lines) src = whitespace_re.sub( |