changeset 31842:c130d092042a

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.
author Pulkit Goyal <7895pulkit@gmail.com>
date Fri, 07 Apr 2017 16:00:44 +0530
parents 9ff5a124d111
children 526e4597cca5
files mercurial/pycompat.py
diffstat 1 files changed, 7 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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