D4969: py3: coerce bytestr to bytes to appease urllib.parse.quote_from_bytes()

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Fri Oct 12 06:47:39 EDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rHG5774fc623a18: py3: coerce bytestr to bytes to appease urllib.parse.quote_from_bytes() (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D4969?vs=11835&id=11859

REVISION DETAIL
  https://phab.mercurial-scm.org/D4969

AFFECTED FILES
  mercurial/urllibcompat.py

CHANGE DETAILS

diff --git a/mercurial/urllibcompat.py b/mercurial/urllibcompat.py
--- a/mercurial/urllibcompat.py
+++ b/mercurial/urllibcompat.py
@@ -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')
 



To: indygreg, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list