hgweb: when constructing or adding to a wsgi environ dict, use native strs
That's what's required of us to work with the WSGI API on Python 3.
Differential Revision: https://phab.mercurial-scm.org/D967
--- a/mercurial/hgweb/request.py Thu Oct 05 14:17:50 2017 -0400
+++ b/mercurial/hgweb/request.py Thu Oct 05 14:22:02 2017 -0400
@@ -59,15 +59,15 @@
for obtaining request parameters, writing HTTP output, etc.
"""
def __init__(self, wsgienv, start_response):
- version = wsgienv['wsgi.version']
+ version = wsgienv[r'wsgi.version']
if (version < (1, 0)) or (version >= (2, 0)):
raise RuntimeError("Unknown and unsupported WSGI version %d.%d"
% version)
- self.inp = wsgienv['wsgi.input']
- self.err = wsgienv['wsgi.errors']
- self.threaded = wsgienv['wsgi.multithread']
- self.multiprocess = wsgienv['wsgi.multiprocess']
- self.run_once = wsgienv['wsgi.run_once']
+ self.inp = wsgienv[r'wsgi.input']
+ self.err = wsgienv[r'wsgi.errors']
+ self.threaded = wsgienv[r'wsgi.multithread']
+ self.multiprocess = wsgienv[r'wsgi.multiprocess']
+ self.run_once = wsgienv[r'wsgi.run_once']
self.env = wsgienv
self.form = normalize(cgi.parse(self.inp,
self.env,
--- a/mercurial/hgweb/server.py Thu Oct 05 14:17:50 2017 -0400
+++ b/mercurial/hgweb/server.py Thu Oct 05 14:22:02 2017 -0400
@@ -63,7 +63,7 @@
"""Prepare .socket of new HTTPServer instance"""
def __init__(self, *args, **kargs):
- self.protocol_version = 'HTTP/1.1'
+ self.protocol_version = r'HTTP/1.1'
httpservermod.basehttprequesthandler.__init__(self, *args, **kargs)
def _log_any(self, fp, format, *args):
@@ -112,45 +112,45 @@
path, query = _splitURI(self.path)
env = {}
- env['GATEWAY_INTERFACE'] = 'CGI/1.1'
- env['REQUEST_METHOD'] = self.command
- env['SERVER_NAME'] = self.server.server_name
- env['SERVER_PORT'] = str(self.server.server_port)
- env['REQUEST_URI'] = self.path
- env['SCRIPT_NAME'] = self.server.prefix
- env['PATH_INFO'] = path[len(self.server.prefix):]
- env['REMOTE_HOST'] = self.client_address[0]
- env['REMOTE_ADDR'] = self.client_address[0]
+ env[r'GATEWAY_INTERFACE'] = r'CGI/1.1'
+ env[r'REQUEST_METHOD'] = self.command
+ env[r'SERVER_NAME'] = self.server.server_name
+ env[r'SERVER_PORT'] = str(self.server.server_port)
+ env[r'REQUEST_URI'] = self.path
+ env[r'SCRIPT_NAME'] = self.server.prefix
+ env[r'PATH_INFO'] = path[len(self.server.prefix):]
+ env[r'REMOTE_HOST'] = self.client_address[0]
+ env[r'REMOTE_ADDR'] = self.client_address[0]
if query:
- env['QUERY_STRING'] = query
+ env[r'QUERY_STRING'] = query
if self.headers.typeheader is None:
- env['CONTENT_TYPE'] = self.headers.type
+ env[r'CONTENT_TYPE'] = self.headers.type
else:
- env['CONTENT_TYPE'] = self.headers.typeheader
+ env[r'CONTENT_TYPE'] = self.headers.typeheader
length = self.headers.getheader('content-length')
if length:
- env['CONTENT_LENGTH'] = length
+ env[r'CONTENT_LENGTH'] = length
for header in [h for h in self.headers.keys()
if h not in ('content-type', 'content-length')]:
- hkey = 'HTTP_' + header.replace('-', '_').upper()
- hval = self.headers.getheader(header)
- hval = hval.replace('\n', '').strip()
+ hkey = r'HTTP_' + header.replace(r'-', r'_').upper()
+ hval = self.headers.get(header)
+ hval = hval.replace(r'\n', r'').strip()
if hval:
env[hkey] = hval
- env['SERVER_PROTOCOL'] = self.request_version
- env['wsgi.version'] = (1, 0)
- env['wsgi.url_scheme'] = self.url_scheme
- if env.get('HTTP_EXPECT', '').lower() == '100-continue':
+ env[r'SERVER_PROTOCOL'] = self.request_version
+ env[r'wsgi.version'] = (1, 0)
+ env[r'wsgi.url_scheme'] = self.url_scheme
+ if env.get(r'HTTP_EXPECT', '').lower() == '100-continue':
self.rfile = common.continuereader(self.rfile, self.wfile.write)
- env['wsgi.input'] = self.rfile
- env['wsgi.errors'] = _error_logger(self)
- env['wsgi.multithread'] = isinstance(self.server,
+ env[r'wsgi.input'] = self.rfile
+ env[r'wsgi.errors'] = _error_logger(self)
+ env[r'wsgi.multithread'] = isinstance(self.server,
socketserver.ThreadingMixIn)
- env['wsgi.multiprocess'] = isinstance(self.server,
+ env[r'wsgi.multiprocess'] = isinstance(self.server,
socketserver.ForkingMixIn)
- env['wsgi.run_once'] = 0
+ env[r'wsgi.run_once'] = 0
self.saved_status = None
self.saved_headers = []
--- a/mercurial/hgweb/wsgicgi.py Thu Oct 05 14:17:50 2017 -0400
+++ b/mercurial/hgweb/wsgicgi.py Thu Oct 05 14:22:02 2017 -0400
@@ -24,28 +24,28 @@
util.setbinary(util.stdout)
environ = dict(encoding.environ.iteritems())
- environ.setdefault('PATH_INFO', '')
- if environ.get('SERVER_SOFTWARE', '').startswith('Microsoft-IIS'):
+ environ.setdefault(r'PATH_INFO', '')
+ if environ.get(r'SERVER_SOFTWARE', r'').startswith(r'Microsoft-IIS'):
# IIS includes script_name in PATH_INFO
- scriptname = environ['SCRIPT_NAME']
- if environ['PATH_INFO'].startswith(scriptname):
- environ['PATH_INFO'] = environ['PATH_INFO'][len(scriptname):]
+ scriptname = environ[r'SCRIPT_NAME']
+ if environ[r'PATH_INFO'].startswith(scriptname):
+ environ[r'PATH_INFO'] = environ[r'PATH_INFO'][len(scriptname):]
stdin = util.stdin
- if environ.get('HTTP_EXPECT', '').lower() == '100-continue':
+ if environ.get(r'HTTP_EXPECT', r'').lower() == r'100-continue':
stdin = common.continuereader(stdin, util.stdout.write)
- environ['wsgi.input'] = stdin
- environ['wsgi.errors'] = util.stderr
- environ['wsgi.version'] = (1, 0)
- environ['wsgi.multithread'] = False
- environ['wsgi.multiprocess'] = True
- environ['wsgi.run_once'] = True
+ environ[r'wsgi.input'] = stdin
+ environ[r'wsgi.errors'] = util.stderr
+ environ[r'wsgi.version'] = (1, 0)
+ environ[r'wsgi.multithread'] = False
+ environ[r'wsgi.multiprocess'] = True
+ environ[r'wsgi.run_once'] = True
- if environ.get('HTTPS', 'off').lower() in ('on', '1', 'yes'):
- environ['wsgi.url_scheme'] = 'https'
+ if environ.get(r'HTTPS', r'off').lower() in (r'on', r'1', r'yes'):
+ environ[r'wsgi.url_scheme'] = r'https'
else:
- environ['wsgi.url_scheme'] = 'http'
+ environ[r'wsgi.url_scheme'] = r'http'
headers_set = []
headers_sent = []