changeset 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 2fd8a8c11273
children 2632c1ed8f34
files mercurial/hgweb/request.py
diffstat 1 files changed, 5 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hgweb/request.py	Tue Jun 23 16:07:18 2020 +0200
+++ b/mercurial/hgweb/request.py	Thu Jun 25 03:10:13 2020 +0200
@@ -162,11 +162,11 @@
     # strings on Python 3 must be between \00000-\000FF. We deal with bytes
     # in Mercurial, so mass convert string keys and values to bytes.
     if pycompat.ispy3:
-        env = {k.encode('latin-1'): v for k, v in pycompat.iteritems(env)}
-        env = {
-            k: v.encode('latin-1') if isinstance(v, str) else v
-            for k, v in pycompat.iteritems(env)
-        }
+        def tobytes(s):
+            if not isinstance(s, str):
+                return s
+            return s.encode('latin-1')
+        env = {tobytes(k): tobytes(v) for k, v in pycompat.iteritems(env)}
 
     # Some hosting solutions are emulating hgwebdir, and dispatching directly
     # to an hgweb instance using this environment variable.  This was always