diff 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
line wrap: on
line diff
--- a/roundup/cgi/cgitb.py	Tue Jun 11 21:05:53 2019 -0400
+++ b/roundup/cgi/cgitb.py	Tue Jun 11 21:29:24 2019 -0400
@@ -10,6 +10,11 @@
 import sys, os, keyword, linecache, tokenize, inspect, cgi
 import pydoc, traceback
 
+try:
+    from html import escape as html_escape  # python 3
+except ImportError:
+    from cgi import escape as html_escape   # python 2 fallback
+
 from roundup.cgi import templating, TranslationService
 from roundup.anypy.strings import s2b
 
@@ -41,12 +46,12 @@
     for k in sorted(dict):
         v = dict[k]
         l.append('<tr><td><strong>%s</strong></td><td>%s</td></tr>'%(k,
-            cgi.escape(repr(v))))
+            html_escape(repr(v))))
     return '\n'.join(l)
 
 def pt_html(context=5, i18n=None):
     _ = get_translator(i18n)
-    esc = cgi.escape
+    esc = html_escape
     exc_info = [esc(str(value)) for value in sys.exc_info()[:2]]
     l = [_('<h1>Templating Error</h1>\n'
             '<p><b>%(exc_type)s</b>: %(exc_value)s</p>\n'
@@ -102,7 +107,7 @@
 <table style="font-size: 80%%; color: gray">
  <tr><th class="header" align="left">%s</th></tr>
  <tr><td><pre>%s</pre></td></tr>
-</table>''' % (_('Full traceback:'), cgi.escape(''.join(
+</table>''' % (_('Full traceback:'), html_escape(''.join(
         traceback.format_exception(*sys.exc_info())
     ))))
     l.append('<p>&nbsp;</p>')

Roundup Issue Tracker: http://roundup-tracker.org/