Mercurial > public > mercurial-scm > hg
comparison mercurial/hgweb/request.py @ 45003:839328c5a728 stable
hgweb: deduplicate code
A following patch will change the way keys and values are encoded. To reduce the
diff, I?ve split off the uninteresting part.
author | Manuel Jacob <me@manueljacob.de> |
---|---|
date | Thu, 25 Jun 2020 03:10:13 +0200 |
parents | 8ff1ecfadcd1 |
children | 2632c1ed8f34 |
comparison
equal
deleted
inserted
replaced
44979:2fd8a8c11273 | 45003:839328c5a728 |
---|---|
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 pycompat.iteritems(env)} | 165 def tobytes(s): |
166 env = { | 166 if not isinstance(s, str): |
167 k: v.encode('latin-1') if isinstance(v, str) else v | 167 return s |
168 for k, v in pycompat.iteritems(env) | 168 return s.encode('latin-1') |
169 } | 169 env = {tobytes(k): tobytes(v) for k, v in pycompat.iteritems(env)} |
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. |
174 if not reponame: | 174 if not reponame: |