Patchwork D967: hgweb: when constructing or adding to a wsgi environ dict, use native strs

login
register
mail settings
Submitter phabricator
Date Oct. 8, 2017, 8:38 a.m.
Message ID <effd19b858cce0c3d30d94d25fba959a@localhost.localdomain>
Download mbox | patch
Permalink /patch/24639/
State Not Applicable
Headers show

Comments

phabricator - Oct. 8, 2017, 8:38 a.m.
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




To: durin42, #hg-reviewers, quark, indygreg
Cc: indygreg, mercurial-devel

Patch

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'] = (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 = []
diff --git a/mercurial/hgweb/request.py b/mercurial/hgweb/request.py
--- a/mercurial/hgweb/request.py
+++ b/mercurial/hgweb/request.py
@@ -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,