D2732: hgweb: rename req to wsgireq
This revision was automatically updated to reflect the committed changes. Closed by commit rHGb9b968e21f78: hgweb: rename req to wsgireq (authored by indygreg, committed by ). REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D2732?vs=6738=6776 REVISION DETAIL https://phab.mercurial-scm.org/D2732 AFFECTED FILES mercurial/hgweb/hgweb_mod.py mercurial/hgweb/hgwebdir_mod.py mercurial/wireprotoserver.py CHANGE DETAILS diff --git a/mercurial/wireprotoserver.py b/mercurial/wireprotoserver.py --- a/mercurial/wireprotoserver.py +++ b/mercurial/wireprotoserver.py @@ -36,26 +36,26 @@ SSHV1 = wireprototypes.SSHV1 SSHV2 = wireprototypes.SSHV2 -def decodevaluefromheaders(req, headerprefix): +def decodevaluefromheaders(wsgireq, headerprefix): """Decode a long value from multiple HTTP request headers. Returns the value as a bytes, not a str. """ chunks = [] i = 1 prefix = headerprefix.upper().replace(r'-', r'_') while True: -v = req.env.get(r'HTTP_%s_%d' % (prefix, i)) +v = wsgireq.env.get(r'HTTP_%s_%d' % (prefix, i)) if v is None: break chunks.append(pycompat.bytesurl(v)) i += 1 return ''.join(chunks) class httpv1protocolhandler(wireprototypes.baseprotocolhandler): -def __init__(self, req, ui, checkperm): -self._req = req +def __init__(self, wsgireq, ui, checkperm): +self._wsgireq = wsgireq self._ui = ui self._checkperm = checkperm @@ -79,26 +79,26 @@ return [data[k] for k in keys] def _args(self): -args = util.rapply(pycompat.bytesurl, self._req.form.copy()) -postlen = int(self._req.env.get(r'HTTP_X_HGARGS_POST', 0)) +args = util.rapply(pycompat.bytesurl, self._wsgireq.form.copy()) +postlen = int(self._wsgireq.env.get(r'HTTP_X_HGARGS_POST', 0)) if postlen: args.update(urlreq.parseqs( -self._req.read(postlen), keep_blank_values=True)) +self._wsgireq.read(postlen), keep_blank_values=True)) return args -argvalue = decodevaluefromheaders(self._req, r'X-HgArg') +argvalue = decodevaluefromheaders(self._wsgireq, r'X-HgArg') args.update(urlreq.parseqs(argvalue, keep_blank_values=True)) return args def forwardpayload(self, fp): -if r'HTTP_CONTENT_LENGTH' in self._req.env: -length = int(self._req.env[r'HTTP_CONTENT_LENGTH']) +if r'HTTP_CONTENT_LENGTH' in self._wsgireq.env: +length = int(self._wsgireq.env[r'HTTP_CONTENT_LENGTH']) else: -length = int(self._req.env[r'CONTENT_LENGTH']) +length = int(self._wsgireq.env[r'CONTENT_LENGTH']) # If httppostargs is used, we need to read Content-Length # minus the amount that was consumed by args. -length -= int(self._req.env.get(r'HTTP_X_HGARGS_POST', 0)) -for s in util.filechunkiter(self._req, limit=length): +length -= int(self._wsgireq.env.get(r'HTTP_X_HGARGS_POST', 0)) +for s in util.filechunkiter(self._wsgireq, limit=length): fp.write(s) @contextlib.contextmanager @@ -118,9 +118,9 @@ def client(self): return 'remote:%s:%s:%s' % ( -self._req.env.get('wsgi.url_scheme') or 'http', -urlreq.quote(self._req.env.get('REMOTE_HOST', '')), -urlreq.quote(self._req.env.get('REMOTE_USER', ''))) +self._wsgireq.env.get('wsgi.url_scheme') or 'http', +urlreq.quote(self._wsgireq.env.get('REMOTE_HOST', '')), +urlreq.quote(self._wsgireq.env.get('REMOTE_USER', ''))) def addcapabilities(self, repo, caps): caps.append('httpheader=%d' % @@ -150,25 +150,25 @@ def iscmd(cmd): return cmd in wireproto.commands -def parsehttprequest(rctx, req, query, checkperm): +def parsehttprequest(rctx, wsgireq, query, checkperm): """Parse the HTTP request for a wire protocol request. If the current request appears to be a wire protocol request, this function returns a dict with details about that request, including an ``abstractprotocolserver`` instance suitable for handling the request. Otherwise, ``None`` is returned. -``req`` is a ``wsgirequest`` instance. +``wsgireq`` is a ``wsgirequest`` instance. """ repo = rctx.repo # HTTP version 1 wire protocol requests are denoted by a "cmd" query # string parameter. If it isn't present, this isn't a wire protocol # request. -if 'cmd' not in req.form: +if 'cmd' not in wsgireq.form: return None -cmd = req.form['cmd'][0] +cmd = wsgireq.form['cmd'][0] # The "cmd" request parameter is used by both the wire protocol and hgweb. # While not all wire protocol commands are available for all transports, @@ -180,24 +180,24 @@ if not iscmd(cmd): return None -proto =
D2732: hgweb: rename req to wsgireq
indygreg created this revision. Herald added a subscriber: mercurial-devel. Herald added a reviewer: hg-reviewers. REVISION SUMMARY We will soon introduce a parsed WSGI request object so we don't have to concern ourselves with low-level WSGI matters. Prepare for multiple request objects by renaming the existing one so it is clear it deals with WSGI. We also remove a symbol import to avoid even more naming confusion. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D2732 AFFECTED FILES mercurial/hgweb/hgweb_mod.py mercurial/hgweb/hgwebdir_mod.py mercurial/wireprotoserver.py CHANGE DETAILS diff --git a/mercurial/wireprotoserver.py b/mercurial/wireprotoserver.py --- a/mercurial/wireprotoserver.py +++ b/mercurial/wireprotoserver.py @@ -36,26 +36,26 @@ SSHV1 = wireprototypes.SSHV1 SSHV2 = wireprototypes.SSHV2 -def decodevaluefromheaders(req, headerprefix): +def decodevaluefromheaders(wsgireq, headerprefix): """Decode a long value from multiple HTTP request headers. Returns the value as a bytes, not a str. """ chunks = [] i = 1 prefix = headerprefix.upper().replace(r'-', r'_') while True: -v = req.env.get(r'HTTP_%s_%d' % (prefix, i)) +v = wsgireq.env.get(r'HTTP_%s_%d' % (prefix, i)) if v is None: break chunks.append(pycompat.bytesurl(v)) i += 1 return ''.join(chunks) class httpv1protocolhandler(wireprototypes.baseprotocolhandler): -def __init__(self, req, ui, checkperm): -self._req = req +def __init__(self, wsgireq, ui, checkperm): +self._wsgireq = wsgireq self._ui = ui self._checkperm = checkperm @@ -79,26 +79,26 @@ return [data[k] for k in keys] def _args(self): -args = util.rapply(pycompat.bytesurl, self._req.form.copy()) -postlen = int(self._req.env.get(r'HTTP_X_HGARGS_POST', 0)) +args = util.rapply(pycompat.bytesurl, self._wsgireq.form.copy()) +postlen = int(self._wsgireq.env.get(r'HTTP_X_HGARGS_POST', 0)) if postlen: args.update(urlreq.parseqs( -self._req.read(postlen), keep_blank_values=True)) +self._wsgireq.read(postlen), keep_blank_values=True)) return args -argvalue = decodevaluefromheaders(self._req, r'X-HgArg') +argvalue = decodevaluefromheaders(self._wsgireq, r'X-HgArg') args.update(urlreq.parseqs(argvalue, keep_blank_values=True)) return args def forwardpayload(self, fp): -if r'HTTP_CONTENT_LENGTH' in self._req.env: -length = int(self._req.env[r'HTTP_CONTENT_LENGTH']) +if r'HTTP_CONTENT_LENGTH' in self._wsgireq.env: +length = int(self._wsgireq.env[r'HTTP_CONTENT_LENGTH']) else: -length = int(self._req.env[r'CONTENT_LENGTH']) +length = int(self._wsgireq.env[r'CONTENT_LENGTH']) # If httppostargs is used, we need to read Content-Length # minus the amount that was consumed by args. -length -= int(self._req.env.get(r'HTTP_X_HGARGS_POST', 0)) -for s in util.filechunkiter(self._req, limit=length): +length -= int(self._wsgireq.env.get(r'HTTP_X_HGARGS_POST', 0)) +for s in util.filechunkiter(self._wsgireq, limit=length): fp.write(s) @contextlib.contextmanager @@ -118,9 +118,9 @@ def client(self): return 'remote:%s:%s:%s' % ( -self._req.env.get('wsgi.url_scheme') or 'http', -urlreq.quote(self._req.env.get('REMOTE_HOST', '')), -urlreq.quote(self._req.env.get('REMOTE_USER', ''))) +self._wsgireq.env.get('wsgi.url_scheme') or 'http', +urlreq.quote(self._wsgireq.env.get('REMOTE_HOST', '')), +urlreq.quote(self._wsgireq.env.get('REMOTE_USER', ''))) def addcapabilities(self, repo, caps): caps.append('httpheader=%d' % @@ -150,25 +150,25 @@ def iscmd(cmd): return cmd in wireproto.commands -def parsehttprequest(rctx, req, query, checkperm): +def parsehttprequest(rctx, wsgireq, query, checkperm): """Parse the HTTP request for a wire protocol request. If the current request appears to be a wire protocol request, this function returns a dict with details about that request, including an ``abstractprotocolserver`` instance suitable for handling the request. Otherwise, ``None`` is returned. -``req`` is a ``wsgirequest`` instance. +``wsgireq`` is a ``wsgirequest`` instance. """ repo = rctx.repo # HTTP version 1 wire protocol requests are denoted by a "cmd" query # string parameter. If it isn't present, this isn't a wire protocol # request. -if 'cmd' not in req.form: +if 'cmd' not in wsgireq.form: return None -cmd = req.form['cmd'][0] +cmd = wsgireq.form['cmd'][0] # The "cmd" request parameter is used by both the wire