diff options
author | ianb <devnull@localhost> | 2006-08-21 20:39:44 +0000 |
---|---|---|
committer | ianb <devnull@localhost> | 2006-08-21 20:39:44 +0000 |
commit | 9b0705d2e06508af198cd4c1ad9504073918611b (patch) | |
tree | 532e5fb147e4b80a73844c7157b216b5101dc755 /paste/exceptions | |
parent | bb9d1385c564cc0ec49ecdd852b3d9b118e4a7d0 (diff) | |
download | paste-9b0705d2e06508af198cd4c1ad9504073918611b.tar.gz |
Fixed problem with exception formatter word wrapping routine
Diffstat (limited to 'paste/exceptions')
-rw-r--r-- | paste/exceptions/formatter.py | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/paste/exceptions/formatter.py b/paste/exceptions/formatter.py index 088c84f..4aa876b 100644 --- a/paste/exceptions/formatter.py +++ b/paste/exceptions/formatter.py @@ -312,7 +312,7 @@ class HTMLFormatter(TextFormatter): % (odd and 'odd' or 'even', self.quote(name))) table.append( '<td><tt>%s</tt></td></tr>' - % make_wrappable(self.quote(value))) + % make_wrappable(self.quote(truncate(value)))) table.append('</table>') return '\n'.join(table) @@ -504,24 +504,39 @@ def _str2html(src, strip=False, indent_subsequent=0, lambda m: ' '*(len(m.group(0))-1) + ' ', src) return src +def truncate(string, limit=1000): + """ + Truncate the string to the limit number of + characters + """ + if len(string) > limit: + return string[:limit-20]+'...'+string[-17:] + else: + return string + def make_wrappable(html, wrap_limit=60, split_on=';?&@!$#-/\\"\''): # Currently using <wbr>, maybe should use ​ # http://www.cs.tut.fi/~jkorpela/html/nobr.html + if len(html) <= wrap_limit: + return html words = html.split() new_words = [] for word in words: - if len(word) > wrap_limit: + wrapped_word = '' + while len(word) > wrap_limit: for char in split_on: if char in word: - words = [ - make_wrappable(w, wrap_limit=wrap_limit, - split_on=split_on) - for w in word.split(char, 1)] - new_words.append('<wbr>'.join(words)) + first, rest = word.split(char, 1) + wrapped_word += first+char+'<wbr>' + word = rest break - else: - new_words.append(word) + else: + for i in range(0, len(word), wrap_limit): + wrapped_word += word[i:i+wrap_limit]+'<wbr>' + word = '' + wrapped_word += word + new_words.append(wrapped_word) return ' '.join(new_words) def make_pre_wrappable(html, wrap_limit=60, |