py3: add a bytes version of urllib.parse.urlencode() to pycompat.py
authorPulkit Goyal <7895pulkit@gmail.com>
Fri, 07 Apr 2017 16:00:44 +0530
changeset 31842 c130d092042a
parent 31841 9ff5a124d111
child 31843 526e4597cca5
py3: add a bytes version of urllib.parse.urlencode() to pycompat.py urllib.parse.urlencode() returns unicodes on Python 3. This commit adds a method which will take its output and encode it to bytes so that we can use bytes consistently.
mercurial/pycompat.py
--- a/mercurial/pycompat.py	Fri Apr 07 13:46:35 2017 +0530
+++ b/mercurial/pycompat.py	Fri Apr 07 16:00:44 2017 +0530
@@ -399,4 +399,11 @@
         s = urllib.parse.quote_from_bytes(s, safe=safe)
         return s.encode('ascii', 'strict')
 
+    # urllib.parse.urlencode() returns str. We use this function to make
+    # sure we return bytes.
+    def urlencode(query, doseq=False):
+            s = urllib.parse.urlencode(query, doseq=doseq)
+            return s.encode('ascii')
+
     urlreq.quote = quote
+    urlreq.urlencode = urlencode