Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hgweb/request.py @ 43106:d783f945a701
py3: finish porting iteritems() to pycompat and remove source transformer
This commit finishes porting .iteritems() to pycompat.iteritems()
for the mercurial package.
The translation of .iteritems() to .items() was the last conversion
performed by the source transformer. With the porting to pycompat
complete, we no longer have a need for the source transformer. So
the source transformer has been removed. Good riddance! The code
base is now compatible with Python 2 and Python 3.
For the record, as the person who introduced the source transformer,
it brings me joy to delete it. It accomplished its goal to facilitate
a port to Python 3 without overly burdening people on some painful
low-level differences between Python 2 and 3. It is unfortunate we
still have to wallpaper over many differences with the pycompat
shim. But it is what it is.
Differential Revision: https://phab.mercurial-scm.org/D7015
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 07 Oct 2019 00:04:04 -0400 |
parents | 687b865b95ad |
children | 8ff1ecfadcd1 |
comparison
equal
deleted
inserted
replaced
43105:649d3ac37a12 | 43106:d783f945a701 |
---|---|
72 raise KeyError(b'multiple values for %r' % key) | 72 raise KeyError(b'multiple values for %r' % key) |
73 | 73 |
74 return vals[0] | 74 return vals[0] |
75 | 75 |
76 def asdictoflists(self): | 76 def asdictoflists(self): |
77 return {k: list(v) for k, v in self._items.iteritems()} | 77 return {k: list(v) for k, v in pycompat.iteritems(self._items)} |
78 | 78 |
79 | 79 |
80 @attr.s(frozen=True) | 80 @attr.s(frozen=True) |
81 class parsedrequest(object): | 81 class parsedrequest(object): |
82 """Represents a parsed WSGI request. | 82 """Represents a parsed WSGI request. |
160 # PEP-0333 states that environment keys and values are native strings | 160 # PEP-0333 states that environment keys and values are native strings |
161 # (bytes on Python 2 and str on Python 3). The code points for the Unicode | 161 # (bytes on Python 2 and str on Python 3). The code points for the Unicode |
162 # strings on Python 3 must be between \00000-\000FF. We deal with bytes | 162 # strings on Python 3 must be between \00000-\000FF. We deal with bytes |
163 # in Mercurial, so mass convert string keys and values to bytes. | 163 # in Mercurial, so mass convert string keys and values to bytes. |
164 if pycompat.ispy3: | 164 if pycompat.ispy3: |
165 env = {k.encode('latin-1'): v for k, v in env.iteritems()} | 165 env = {k.encode('latin-1'): v for k, v in pycompat.iteritems(env)} |
166 env = { | 166 env = { |
167 k: v.encode('latin-1') if isinstance(v, str) else v | 167 k: v.encode('latin-1') if isinstance(v, str) else v |
168 for k, v in env.iteritems() | 168 for k, v in pycompat.iteritems(env) |
169 } | 169 } |
170 | 170 |
171 # Some hosting solutions are emulating hgwebdir, and dispatching directly | 171 # Some hosting solutions are emulating hgwebdir, and dispatching directly |
172 # to an hgweb instance using this environment variable. This was always | 172 # to an hgweb instance using this environment variable. This was always |
173 # checked prior to d7fd203e36cc; keep doing so to avoid breaking them. | 173 # checked prior to d7fd203e36cc; keep doing so to avoid breaking them. |
298 | 298 |
299 # HTTP_* keys contain HTTP request headers. The Headers structure should | 299 # HTTP_* keys contain HTTP request headers. The Headers structure should |
300 # perform case normalization for us. We just rewrite underscore to dash | 300 # perform case normalization for us. We just rewrite underscore to dash |
301 # so keys match what likely went over the wire. | 301 # so keys match what likely went over the wire. |
302 headers = [] | 302 headers = [] |
303 for k, v in env.iteritems(): | 303 for k, v in pycompat.iteritems(env): |
304 if k.startswith(b'HTTP_'): | 304 if k.startswith(b'HTTP_'): |
305 headers.append((k[len(b'HTTP_') :].replace(b'_', b'-'), v)) | 305 headers.append((k[len(b'HTTP_') :].replace(b'_', b'-'), v)) |
306 | 306 |
307 from . import wsgiheaders # avoid cycle | 307 from . import wsgiheaders # avoid cycle |
308 | 308 |