Mercurial > p > roundup > code
comparison roundup/scripts/roundup_server.py @ 5431:4c724ad7b849
Python 3 preparation: write bytes to socket in roundup_server.py.
| author | Joseph Myers <jsm@polyomino.org.uk> |
|---|---|
| date | Wed, 25 Jul 2018 10:40:38 +0000 |
| parents | 5dc27422f3ec |
| children | fec18298ae02 |
comparison
equal
deleted
inserted
replaced
| 5430:407c75df2851 | 5431:4c724ad7b849 |
|---|---|
| 61 from roundup import configuration, version_check | 61 from roundup import configuration, version_check |
| 62 from roundup import __version__ as roundup_version | 62 from roundup import __version__ as roundup_version |
| 63 | 63 |
| 64 # Roundup modules of use here | 64 # Roundup modules of use here |
| 65 from roundup.anypy import http_, urllib_ | 65 from roundup.anypy import http_, urllib_ |
| 66 from roundup.anypy.strings import StringIO | 66 from roundup.anypy.strings import s2b, StringIO |
| 67 from roundup.cgi import cgitb, client | 67 from roundup.cgi import cgitb, client |
| 68 from roundup.cgi.PageTemplates.PageTemplate import PageTemplate | 68 from roundup.cgi.PageTemplates.PageTemplate import PageTemplate |
| 69 import roundup.instance | 69 import roundup.instance |
| 70 from roundup.i18n import _ | 70 from roundup.i18n import _ |
| 71 | 71 |
| 235 self.send_header('Content-Type', 'text/html') | 235 self.send_header('Content-Type', 'text/html') |
| 236 self.end_headers() | 236 self.end_headers() |
| 237 if self.DEBUG_MODE: | 237 if self.DEBUG_MODE: |
| 238 try: | 238 try: |
| 239 reload(cgitb) | 239 reload(cgitb) |
| 240 self.wfile.write(cgitb.breaker()) | 240 self.wfile.write(s2b(cgitb.breaker())) |
| 241 self.wfile.write(cgitb.html()) | 241 self.wfile.write(s2b(cgitb.html())) |
| 242 except: | 242 except: |
| 243 s = StringIO() | 243 s = StringIO() |
| 244 traceback.print_exc(None, s) | 244 traceback.print_exc(None, s) |
| 245 self.wfile.write("<pre>") | 245 self.wfile.write(b"<pre>") |
| 246 self.wfile.write(cgi.escape(s.getvalue())) | 246 self.wfile.write(s2b(cgi.escape(s.getvalue()))) |
| 247 self.wfile.write("</pre>\n") | 247 self.wfile.write(b"</pre>\n") |
| 248 else: | 248 else: |
| 249 # user feedback | 249 # user feedback |
| 250 self.wfile.write(cgitb.breaker()) | 250 self.wfile.write(s2b(cgitb.breaker())) |
| 251 ts = time.ctime() | 251 ts = time.ctime() |
| 252 self.wfile.write('''<p>%s: An error occurred. Please check | 252 self.wfile.write(s2b('''<p>%s: An error occurred. Please check |
| 253 the server log for more information.</p>'''%ts) | 253 the server log for more information.</p>'''%ts)) |
| 254 # out to the logfile | 254 # out to the logfile |
| 255 print('EXCEPTION AT', ts) | 255 print('EXCEPTION AT', ts) |
| 256 traceback.print_exc() | 256 traceback.print_exc() |
| 257 | 257 |
| 258 do_GET = do_POST = do_HEAD = run_cgi | 258 do_GET = do_POST = do_HEAD = run_cgi |
| 279 extra = { 'trackers': self.TRACKERS, | 279 extra = { 'trackers': self.TRACKERS, |
| 280 'nothing' : None, | 280 'nothing' : None, |
| 281 'true' : 1, | 281 'true' : 1, |
| 282 'false' : 0, | 282 'false' : 0, |
| 283 } | 283 } |
| 284 w(pt.pt_render(extra_context=extra)) | 284 w(s2b(pt.pt_render(extra_context=extra))) |
| 285 else: | 285 else: |
| 286 w(_('<html><head><title>Roundup trackers index</title></head>\n' | 286 w(s2b(_('<html><head><title>Roundup trackers index</title></head>\n' |
| 287 '<body><h1>Roundup trackers index</h1><ol>\n')) | 287 '<body><h1>Roundup trackers index</h1><ol>\n'))) |
| 288 keys.sort() | 288 keys.sort() |
| 289 for tracker in keys: | 289 for tracker in keys: |
| 290 w('<li><a href="%(tracker_url)s/index">%(tracker_name)s</a>\n'%{ | 290 w(s2b('<li><a href="%(tracker_url)s/index">%(tracker_name)s</a>\n'%{ |
| 291 'tracker_url': urllib_.quote(tracker), | 291 'tracker_url': urllib_.quote(tracker), |
| 292 'tracker_name': cgi.escape(tracker)}) | 292 'tracker_name': cgi.escape(tracker)})) |
| 293 w('</ol></body></html>') | 293 w(b'</ol></body></html>') |
| 294 | 294 |
| 295 def inner_run_cgi(self): | 295 def inner_run_cgi(self): |
| 296 ''' This is the inner part of the CGI handling | 296 ''' This is the inner part of the CGI handling |
| 297 ''' | 297 ''' |
| 298 | 298 |
| 357 url = '%s://%s%s/'%(protocol, self.headers['host'], rest) | 357 url = '%s://%s%s/'%(protocol, self.headers['host'], rest) |
| 358 if query: | 358 if query: |
| 359 url += '?' + query | 359 url += '?' + query |
| 360 self.send_header('Location', url) | 360 self.send_header('Location', url) |
| 361 self.end_headers() | 361 self.end_headers() |
| 362 self.wfile.write('Moved Permanently') | 362 self.wfile.write(b'Moved Permanently') |
| 363 return | 363 return |
| 364 | 364 |
| 365 # figure out what the rest of the path is | 365 # figure out what the rest of the path is |
| 366 if len(l_path) > 2: | 366 if len(l_path) > 2: |
| 367 rest = '/'.join(l_path[2:]) | 367 rest = '/'.join(l_path[2:]) |
