changeset 40159:5774fc623a18

py3: coerce bytestr to bytes to appease urllib.parse.quote_from_bytes() Differential Revision: https://phab.mercurial-scm.org/D4969
author Gregory Szorc <gregory.szorc@gmail.com>
date Thu, 11 Oct 2018 22:26:12 +0200
parents 9310037f0636
children 6037c49b8964
files mercurial/urllibcompat.py
diffstat 1 files changed, 4 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/urllibcompat.py	Thu Oct 11 21:47:39 2018 +0200
+++ b/mercurial/urllibcompat.py	Thu Oct 11 22:26:12 2018 +0200
@@ -92,6 +92,10 @@
     # (if necessary), and returns str. This is wonky. We provide a custom
     # implementation that only accepts bytes and emits bytes.
     def quote(s, safe=r'/'):
+        # bytestr has an __iter__ that emits characters. quote_from_bytes()
+        # does an iteration and expects ints. We coerce to bytes to appease it.
+        if isinstance(s, pycompat.bytestr):
+            s = bytes(s)
         s = urllib.parse.quote_from_bytes(s, safe=safe)
         return s.encode('ascii', 'strict')