Patchwork [2,of,3,V2] py3: add a bytes version of urllib.parse.urlencode() to pycompat.py

login
register
mail settings
Submitter Pulkit Goyal
Date April 7, 2017, 6:38 p.m.
Message ID <1724a314de7c22936d33.1491590304@pulkit-goyal>
Download mbox | patch
Permalink /patch/20007/
State Accepted
Headers show

Comments

Pulkit Goyal - April 7, 2017, 6:38 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1491561044 -19800
#      Fri Apr 07 16:00:44 2017 +0530
# Node ID 1724a314de7c22936d33b09066e9f06197437391
# Parent  50b531cb22c78a068c5effd84eb3c931187b5b71
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.

Patch

diff -r 50b531cb22c7 -r 1724a314de7c 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