Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/pycompat.py @ 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 | 45761ef1bc93 |
children | 526e4597cca5 |
comparison
equal
deleted
inserted
replaced
31841:9ff5a124d111 | 31842:c130d092042a |
---|---|
397 # implementation that only accepts bytes and emits bytes. | 397 # implementation that only accepts bytes and emits bytes. |
398 def quote(s, safe=r'/'): | 398 def quote(s, safe=r'/'): |
399 s = urllib.parse.quote_from_bytes(s, safe=safe) | 399 s = urllib.parse.quote_from_bytes(s, safe=safe) |
400 return s.encode('ascii', 'strict') | 400 return s.encode('ascii', 'strict') |
401 | 401 |
402 # urllib.parse.urlencode() returns str. We use this function to make | |
403 # sure we return bytes. | |
404 def urlencode(query, doseq=False): | |
405 s = urllib.parse.urlencode(query, doseq=doseq) | |
406 return s.encode('ascii') | |
407 | |
402 urlreq.quote = quote | 408 urlreq.quote = quote |
409 urlreq.urlencode = urlencode |