comparison roundup/cgi/wsgi_handler.py @ 5539:3a07c57d72bb

Handle string-to-bytes conversions for Python 3 for wsgi_handler.
author Joseph Myers <jsm@polyomino.org.uk>
date Sat, 15 Sep 2018 20:29:31 +0000
parents 277e91bf7936
children dccf9b7e5ee4
comparison
equal deleted inserted replaced
5538:2692a1c48484 5539:3a07c57d72bb
9 import weakref 9 import weakref
10 10
11 import roundup.instance 11 import roundup.instance
12 from roundup.cgi import TranslationService 12 from roundup.cgi import TranslationService
13 from roundup.anypy import http_ 13 from roundup.anypy import http_
14 from roundup.anypy.strings import s2b
14 BaseHTTPRequestHandler = http_.server.BaseHTTPRequestHandler 15 BaseHTTPRequestHandler = http_.server.BaseHTTPRequestHandler
15 DEFAULT_ERROR_MESSAGE = http_.server.DEFAULT_ERROR_MESSAGE 16 DEFAULT_ERROR_MESSAGE = http_.server.DEFAULT_ERROR_MESSAGE
16 17
17 18
18 class Writer(object): 19 class Writer(object):
48 if environ ['REQUEST_METHOD'] == 'OPTIONS': 49 if environ ['REQUEST_METHOD'] == 'OPTIONS':
49 code = 501 50 code = 501
50 message, explain = BaseHTTPRequestHandler.responses[code] 51 message, explain = BaseHTTPRequestHandler.responses[code]
51 request.start_response([('Content-Type', 'text/html'), 52 request.start_response([('Content-Type', 'text/html'),
52 ('Connection', 'close')], code) 53 ('Connection', 'close')], code)
53 request.wfile.write(DEFAULT_ERROR_MESSAGE % locals()) 54 request.wfile.write(s2b(DEFAULT_ERROR_MESSAGE % locals()))
54 return [] 55 return []
55 56
56 tracker = roundup.instance.open(self.home, not self.debug) 57 tracker = roundup.instance.open(self.home, not self.debug)
57 58
58 # need to strip the leading '/' 59 # need to strip the leading '/'
66 request.translator) 67 request.translator)
67 try: 68 try:
68 client.main() 69 client.main()
69 except roundup.cgi.client.NotFound: 70 except roundup.cgi.client.NotFound:
70 request.start_response([('Content-Type', 'text/html')], 404) 71 request.start_response([('Content-Type', 'text/html')], 404)
71 request.wfile.write('Not found: %s'%client.path) 72 request.wfile.write(s2b('Not found: %s'%client.path))
72 73
73 # all body data has been written using wfile 74 # all body data has been written using wfile
74 return [] 75 return []
75 76
76 def start_response(self, headers, response_code): 77 def start_response(self, headers, response_code):

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