Patchwork [1,of,2,stable] hgweb: deduplicate code

login
register
mail settings
Submitter Manuel Jacob
Date June 25, 2020, 3:13 a.m.
Message ID <8f730a30fb20a104bbf5.1593054839@tmp>
Download mbox | patch
Permalink /patch/46559/
State New
Headers show

Comments

Manuel Jacob - June 25, 2020, 3:13 a.m.
# HG changeset patch
# User Manuel Jacob <me@manueljacob.de>
# Date 1593047413 -7200
#      Thu Jun 25 03:10:13 2020 +0200
# Branch stable
# Node ID 8f730a30fb20a104bbf5665e1f7d0d4e4aaedf6f
# Parent  3d41172f2ac9ae7b644f3e5f239c28e895f1c4fa
# EXP-Topic cgi_env_encoding
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.

Patch

diff --git a/mercurial/hgweb/request.py b/mercurial/hgweb/request.py
--- a/mercurial/hgweb/request.py
+++ b/mercurial/hgweb/request.py
@@ -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