From 9b0705d2e06508af198cd4c1ad9504073918611b Mon Sep 17 00:00:00 2001 From: ianb Date: Mon, 21 Aug 2006 20:39:44 +0000 Subject: Fixed problem with exception formatter word wrapping routine --- paste/exceptions/formatter.py | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'paste/exceptions') 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( '%s' - % make_wrappable(self.quote(value))) + % make_wrappable(self.quote(truncate(value)))) table.append('') 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 , 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(''.join(words)) + first, rest = word.split(char, 1) + wrapped_word += first+char+'' + 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]+'' + word = '' + wrapped_word += word + new_words.append(wrapped_word) return ' '.join(new_words) def make_pre_wrappable(html, wrap_limit=60, -- cgit v1.2.1