Mercurial > p > roundup > code
comparison roundup/cgi/cgitb.py @ 5800:1a835db41674
Call cgi.escape only on python 2. Replace with html.escapeif it can be
found.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Tue, 11 Jun 2019 21:29:24 -0400 |
| parents | e70fe1d1215b |
| children | 883c9e90b403 |
comparison
equal
deleted
inserted
replaced
| 5799:7ba0ee980fc7 | 5800:1a835db41674 |
|---|---|
| 7 from __future__ import print_function | 7 from __future__ import print_function |
| 8 __docformat__ = 'restructuredtext' | 8 __docformat__ = 'restructuredtext' |
| 9 | 9 |
| 10 import sys, os, keyword, linecache, tokenize, inspect, cgi | 10 import sys, os, keyword, linecache, tokenize, inspect, cgi |
| 11 import pydoc, traceback | 11 import pydoc, traceback |
| 12 | |
| 13 try: | |
| 14 from html import escape as html_escape # python 3 | |
| 15 except ImportError: | |
| 16 from cgi import escape as html_escape # python 2 fallback | |
| 12 | 17 |
| 13 from roundup.cgi import templating, TranslationService | 18 from roundup.cgi import templating, TranslationService |
| 14 from roundup.anypy.strings import s2b | 19 from roundup.anypy.strings import s2b |
| 15 | 20 |
| 16 def get_translator(i18n=None): | 21 def get_translator(i18n=None): |
| 39 def niceDict(indent, dict): | 44 def niceDict(indent, dict): |
| 40 l = [] | 45 l = [] |
| 41 for k in sorted(dict): | 46 for k in sorted(dict): |
| 42 v = dict[k] | 47 v = dict[k] |
| 43 l.append('<tr><td><strong>%s</strong></td><td>%s</td></tr>'%(k, | 48 l.append('<tr><td><strong>%s</strong></td><td>%s</td></tr>'%(k, |
| 44 cgi.escape(repr(v)))) | 49 html_escape(repr(v)))) |
| 45 return '\n'.join(l) | 50 return '\n'.join(l) |
| 46 | 51 |
| 47 def pt_html(context=5, i18n=None): | 52 def pt_html(context=5, i18n=None): |
| 48 _ = get_translator(i18n) | 53 _ = get_translator(i18n) |
| 49 esc = cgi.escape | 54 esc = html_escape |
| 50 exc_info = [esc(str(value)) for value in sys.exc_info()[:2]] | 55 exc_info = [esc(str(value)) for value in sys.exc_info()[:2]] |
| 51 l = [_('<h1>Templating Error</h1>\n' | 56 l = [_('<h1>Templating Error</h1>\n' |
| 52 '<p><b>%(exc_type)s</b>: %(exc_value)s</p>\n' | 57 '<p><b>%(exc_type)s</b>: %(exc_value)s</p>\n' |
| 53 '<p class="help">Debugging information follows</p>' | 58 '<p class="help">Debugging information follows</p>' |
| 54 ) % {'exc_type': exc_info[0], 'exc_value': exc_info[1]}, | 59 ) % {'exc_type': exc_info[0], 'exc_value': exc_info[1]}, |
| 100 l.append(''' | 105 l.append(''' |
| 101 </ol> | 106 </ol> |
| 102 <table style="font-size: 80%%; color: gray"> | 107 <table style="font-size: 80%%; color: gray"> |
| 103 <tr><th class="header" align="left">%s</th></tr> | 108 <tr><th class="header" align="left">%s</th></tr> |
| 104 <tr><td><pre>%s</pre></td></tr> | 109 <tr><td><pre>%s</pre></td></tr> |
| 105 </table>''' % (_('Full traceback:'), cgi.escape(''.join( | 110 </table>''' % (_('Full traceback:'), html_escape(''.join( |
| 106 traceback.format_exception(*sys.exc_info()) | 111 traceback.format_exception(*sys.exc_info()) |
| 107 )))) | 112 )))) |
| 108 l.append('<p> </p>') | 113 l.append('<p> </p>') |
| 109 return '\n'.join(l) | 114 return '\n'.join(l) |
| 110 | 115 |
