mercurial/pycompat.py
changeset 31409 fb1f70331ee6
parent 31408 1ed169c5e235
child 31433 4acc49335a6e
--- a/mercurial/pycompat.py	Mon Mar 13 12:14:17 2017 -0700
+++ b/mercurial/pycompat.py	Mon Mar 13 12:16:47 2017 -0700
@@ -269,7 +269,6 @@
 else:
     import urllib.parse
     urlreq._registeraliases(urllib.parse, (
-        "quote",
         "splitattr",
         "splitpasswd",
         "splitport",
@@ -313,3 +312,12 @@
         "SimpleHTTPRequestHandler",
         "CGIHTTPRequestHandler",
     ))
+
+    # urllib.parse.quote() accepts both str and bytes, decodes bytes
+    # (if necessary), and returns str. This is wonky. We provide a custom
+    # implementation that only accepts bytes and emits bytes.
+    def quote(s, safe=r'/'):
+        s = urllib.parse.quote_from_bytes(s, safe=safe)
+        return s.encode('ascii', 'strict')
+
+    urlreq.quote = quote