[PATCH 4 of 4] py3: add a bytes version of urllib.parse.urlencode() to pycompat.py
Yuya Nishihara
yuya at tcha.org
Fri Apr 7 12:18:36 UTC 2017
On Fri, 07 Apr 2017 16:29:40 +0530, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit at gmail.com>
> # Date 1491561044 -19800
> # Fri Apr 07 16:00:44 2017 +0530
> # Node ID c3e934121b61d54184e914bda587281b4184eabf
> # Parent beedb62e62a78a2f45ef8bd0b72c51f14619ee7f
> 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.
>
> diff -r beedb62e62a7 -r c3e934121b61 mercurial/pycompat.py
> --- a/mercurial/pycompat.py Fri Apr 07 15:58:04 2017 +0530
> +++ b/mercurial/pycompat.py Fri Apr 07 16:00:44 2017 +0530
> @@ -399,4 +399,12 @@
> 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, safe='', encoding=None, errors=None):
Nit: better to not provide safe, encoding and errors arguments which don't
exist in Python 3. Other than that, the patch looks good to me.
> + s = urllib.parse.urlencode(query, doseq=doseq, safe=safe,
> + encoding=encoding, errors=errors)
> + return s.encode('ascii')
More information about the Mercurial-devel
mailing list