diff options
| author | ianb <devnull@localhost> | 2005-11-05 03:11:40 +0000 |
|---|---|---|
| committer | ianb <devnull@localhost> | 2005-11-05 03:11:40 +0000 |
| commit | af58a3a3c216bb5ee9fd8a04d613d72f0b6c0aba (patch) | |
| tree | 5f41240e65041ecef3df7234e1eb7e3bc09dba72 /paste/exceptions/formatter.py | |
| parent | 6e0a0c1ca9ea0b81c40d7bb5ddf98edb7c4acd74 (diff) | |
| download | paste-af58a3a3c216bb5ee9fd8a04d613d72f0b6c0aba.tar.gz | |
Fixed case when the code could not be highlighted because it is too invalid; fixed tests that broke due to change of output
Diffstat (limited to 'paste/exceptions/formatter.py')
| -rw-r--r-- | paste/exceptions/formatter.py | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/paste/exceptions/formatter.py b/paste/exceptions/formatter.py index 06ba8a0..e47d73d 100644 --- a/paste/exceptions/formatter.py +++ b/paste/exceptions/formatter.py @@ -475,13 +475,27 @@ pre_re = re.compile(r'</?pre.*?>') error_re = re.compile(r'<h3>ERROR: .*?</h3>') def str2html(src, strip=False, indent_subsequent=0): + """ + 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) + except: + return html_quote(src) + +def _str2html(src, strip=False, indent_subsequent=0): if strip: src = src.strip() - src = PySourceColor.str2html(src, form='snip') - src = error_re.sub('', src) - src = pre_re.sub('', src) - src = re.sub(r'^[\n\r]{0,1}', '', src) - src = re.sub(r'[\n\r]{0,1}$', '', src) + orig_src = src + try: + src = PySourceColor.str2html(src, form='snip') + src = error_re.sub('', src) + src = pre_re.sub('', src) + src = re.sub(r'^[\n\r]{0,1}', '', src) + src = re.sub(r'[\n\r]{0,1}$', '', src) + except: + src = html_quote(orig_src) lines = src.splitlines() if len(lines) == 1: return lines[0] @@ -494,3 +508,5 @@ def str2html(src, strip=False, indent_subsequent=0): src = whitespace_re.sub( lambda m: ' '*(len(m.group(0))-1) + ' ', src) return src + + |
