D967: hgweb: when constructing or adding to a wsgi environ dict, use native strs
durin42 created this revision. Herald added a subscriber: mercurial-devel. Herald added a reviewer: hg-reviewers. REVISION SUMMARY That's what's required of us to work with the WSGI API on Python 3. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D967 AFFECTED FILES mercurial/hgweb/request.py mercurial/hgweb/server.py mercurial/hgweb/wsgicgi.py CHANGE DETAILS diff --git a/mercurial/hgweb/wsgicgi.py b/mercurial/hgweb/wsgicgi.py --- a/mercurial/hgweb/wsgicgi.py +++ b/mercurial/hgweb/wsgicgi.py @@ -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 = [] diff --git a/mercurial/hgweb/server.py b/mercurial/hgweb/server.py --- a/mercurial/hgweb/server.py +++ b/mercurial/hgweb/server.py @@ -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']
D967: hgweb: when constructing or adding to a wsgi environ dict, use native strs
indygreg accepted this revision. indygreg added a comment. This revision is now accepted and ready to land. Dear Python: why are things this close to the wire not bytes? *sigh* REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D967 To: durin42, #hg-reviewers, quark, indygreg Cc: indygreg, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D967: hgweb: when constructing or adding to a wsgi environ dict, use native strs
This revision was automatically updated to reflect the committed changes. Closed by commit rHG147665d36088: hgweb: when constructing or adding to a wsgi environ dict, use native strs (authored by durin42, committed by ). REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D967?vs=2483&id=2529 REVISION DETAIL https://phab.mercurial-scm.org/D967 AFFECTED FILES mercurial/hgweb/request.py mercurial/hgweb/server.py mercurial/hgweb/wsgicgi.py CHANGE DETAILS diff --git a/mercurial/hgweb/wsgicgi.py b/mercurial/hgweb/wsgicgi.py --- a/mercurial/hgweb/wsgicgi.py +++ b/mercurial/hgweb/wsgicgi.py @@ -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 = [] diff --git a/mercurial/hgweb/server.py b/mercurial/hgweb/server.py --- a/mercurial/hgweb/server.py +++ b/mercurial/hgweb/server.py @@ -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: