equal
deleted
inserted
replaced
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 |