hgweb: remove Python 3 conditional
authorGregory Szorc <gregory.szorc@gmail.com>
Thu, 03 Mar 2022 08:06:37 -0800
changeset 48905 7eebe5630bcc
parent 48904 7dc430b85351
child 48906 e453c69821f8
hgweb: remove Python 3 conditional We probably have a better tobytes() implementation somewhere in pycompat. But I don't want to bloat scope of this commit. Differential Revision: https://phab.mercurial-scm.org/D12308
mercurial/hgweb/request.py
--- a/mercurial/hgweb/request.py	Mon Feb 21 10:45:24 2022 -0700
+++ b/mercurial/hgweb/request.py	Thu Mar 03 08:06:37 2022 -0800
@@ -160,24 +160,22 @@
     # TODO enable this once we fix internal violations.
     # wsgiref.validate.check_environ(env)
 
-    # PEP-0333 states that environment keys and values are native strings
-    # (bytes on Python 2 and str on Python 3). The code points for the Unicode
-    # 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:
+    # PEP-0333 states that environment keys and values are native strings.
+    # The code points for the Unicode strings on Python 3 must be between
+    # \00000-\000FF. We deal with bytes in Mercurial, so mass convert string
+    # keys and values to bytes.
+    def tobytes(s):
+        if not isinstance(s, str):
+            return s
+        if pycompat.iswindows:
+            # This is what mercurial.encoding does for os.environ on
+            # Windows.
+            return encoding.strtolocal(s)
+        else:
+            # This is what is documented to be used for os.environ on Unix.
+            return pycompat.fsencode(s)
 
-        def tobytes(s):
-            if not isinstance(s, str):
-                return s
-            if pycompat.iswindows:
-                # This is what mercurial.encoding does for os.environ on
-                # Windows.
-                return encoding.strtolocal(s)
-            else:
-                # This is what is documented to be used for os.environ on Unix.
-                return pycompat.fsencode(s)
-
-        env = {tobytes(k): tobytes(v) for k, v in pycompat.iteritems(env)}
+    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