diff options
| author | ianb <devnull@localhost> | 2005-11-06 10:38:00 +0000 |
|---|---|---|
| committer | ianb <devnull@localhost> | 2005-11-06 10:38:00 +0000 |
| commit | 2e08284f556e061ed78836f649e71caa54bfd5d5 (patch) | |
| tree | acef354087a8bca5703fc29f2687dd6d686b562c /paste/exceptions | |
| parent | ec1df88f85ab87ac0ee4dfff5f399fb77d059687 (diff) | |
| download | paste-2e08284f556e061ed78836f649e71caa54bfd5d5.tar.gz | |
Further refactoring and expansion of the eval exception middleware; functions now, but not that fancy yet
Diffstat (limited to 'paste/exceptions')
| -rw-r--r-- | paste/exceptions/formatter.py | 60 |
1 files changed, 38 insertions, 22 deletions
diff --git a/paste/exceptions/formatter.py b/paste/exceptions/formatter.py index eb71ce4..d50de94 100644 --- a/paste/exceptions/formatter.py +++ b/paste/exceptions/formatter.py @@ -313,30 +313,10 @@ class HTMLFormatter(TextFormatter): % (odd and 'odd' or 'even', self.quote(name))) table.append( '<td><tt>%s</tt></td></tr>' - % self.make_wrappable(self.quote(value))) + % make_wrappable(self.quote(value))) table.append('</table>') return '\n'.join(table) - def make_wrappable(self, html, wrap_limit=60, - split_on=';?&@!$#-/\\"\''): - # Currently using <wbr>, maybe should use ​ - # http://www.cs.tut.fi/~jkorpela/html/nobr.html - words = html.split() - new_words = [] - for word in words: - if len(word) > wrap_limit: - for char in split_on: - if char in word: - words = [ - self.make_wrappable(w, wrap_limit=wrap_limit, - split_on=split_on) - for w in word.split(char, 1)] - new_words.append('<wbr>'.join(words)) - break - else: - new_words.append(word) - return ' '.join(new_words) - hide_display_js = r''' <script type="text/javascript"> function hide_display(id) { @@ -513,4 +493,40 @@ def _str2html(src, strip=False, indent_subsequent=0): lambda m: ' '*(len(m.group(0))-1) + ' ', src) return src - +def make_wrappable(html, wrap_limit=60, + split_on=';?&@!$#-/\\"\''): + # Currently using <wbr>, maybe should use ​ + # http://www.cs.tut.fi/~jkorpela/html/nobr.html + words = html.split() + new_words = [] + for word in words: + if 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)) + break + else: + new_words.append(word) + return ' '.join(new_words) + +def make_pre_wrappable(html, wrap_limit=60, + split_on=';?&@!$#-/\\"\''): + """ + Like ``make_wrappable()`` but intended for text that will + go in a ``<pre>`` block, so wrap on a line-by-line basis. + """ + lines = html.splitlines() + new_lines = [] + for line in lines: + if len(line) > wrap_limit: + for char in split_on: + if char in line: + parts = line.split(char) + line = '<wbr>'.join(parts) + break + new_lines.append(line) + return '\n'.join(lines) |
