comparison roundup/scripts/roundup_server.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 320a1692a473
children 883c9e90b403
comparison
equal deleted inserted replaced
5799:7ba0ee980fc7 5800:1a835db41674
34 # the script is located inside roundup source code 34 # the script is located inside roundup source code
35 sys.path.insert(0, rootdir) 35 sys.path.insert(0, rootdir)
36 # --/ 36 # --/
37 37
38 38
39 import errno, cgi, getopt, io, os, socket, sys, traceback, time 39 import errno, getopt, io, os, socket, sys, traceback, time
40 40
41 try: 41 try:
42 # Python 3. 42 # Python 3.
43 import socketserver 43 import socketserver
44 except ImportError: 44 except ImportError:
54 54
55 try: 55 try:
56 from OpenSSL import SSL 56 from OpenSSL import SSL
57 except ImportError: 57 except ImportError:
58 SSL = None 58 SSL = None
59
60 try:
61 from html import escape as html_escape # python 3
62 except ImportError:
63 from cgi import escape as html_escape # python 2 fallback
59 64
60 # python version check 65 # python version check
61 from roundup import configuration, version_check 66 from roundup import configuration, version_check
62 from roundup import __version__ as roundup_version 67 from roundup import __version__ as roundup_version
63 68
241 self.wfile.write(s2b(cgitb.html())) 246 self.wfile.write(s2b(cgitb.html()))
242 except: 247 except:
243 s = StringIO() 248 s = StringIO()
244 traceback.print_exc(None, s) 249 traceback.print_exc(None, s)
245 self.wfile.write(b"<pre>") 250 self.wfile.write(b"<pre>")
246 self.wfile.write(s2b(cgi.escape(s.getvalue()))) 251 self.wfile.write(s2b(html_escape(s.getvalue())))
247 self.wfile.write(b"</pre>\n") 252 self.wfile.write(b"</pre>\n")
248 else: 253 else:
249 # user feedback 254 # user feedback
250 self.wfile.write(s2b(cgitb.breaker())) 255 self.wfile.write(s2b(cgitb.breaker()))
251 ts = time.ctime() 256 ts = time.ctime()
287 '<body><h1>Roundup trackers index</h1><ol>\n'))) 292 '<body><h1>Roundup trackers index</h1><ol>\n')))
288 keys.sort() 293 keys.sort()
289 for tracker in keys: 294 for tracker in keys:
290 w(s2b('<li><a href="%(tracker_url)s/index">%(tracker_name)s</a>\n'%{ 295 w(s2b('<li><a href="%(tracker_url)s/index">%(tracker_name)s</a>\n'%{
291 'tracker_url': urllib_.quote(tracker), 296 'tracker_url': urllib_.quote(tracker),
292 'tracker_name': cgi.escape(tracker)})) 297 'tracker_name': html_escape(tracker)}))
293 w(b'</ol></body></html>') 298 w(b'</ol></body></html>')
294 299
295 def inner_run_cgi(self): 300 def inner_run_cgi(self):
296 ''' This is the inner part of the CGI handling 301 ''' This is the inner part of the CGI handling
297 ''' 302 '''

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