Patchwork D2144: py3: more robustly cast UUID to bytes

login
register
mail settings
Submitter phabricator
Date Feb. 11, 2018, 10:57 p.m.
Message ID <differential-rev-PHID-DREV-h6j6b54hkihebwzakbcb-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/27588/
State Superseded
Headers show

Comments

phabricator - Feb. 11, 2018, 10:57 p.m.
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  The UUID type only has __str__ implemented. So we need to cast to
  bytes on Python 3.
  
  We need an actual bytes instance here (bytestr won't do) because
  the re.escape() later iterates over characters and characters
  need to behave like ints, not bytes instances of length 1.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/sshpeer.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/sshpeer.py b/mercurial/sshpeer.py
--- a/mercurial/sshpeer.py
+++ b/mercurial/sshpeer.py
@@ -220,7 +220,7 @@ 
 
     # Generate a random token to help identify responses to version 2
     # upgrade request.
-    token = bytes(uuid.uuid4())
+    token = pycompat.sysbytes(str(uuid.uuid4()))
     upgradecaps = [
         ('proto', wireprotoserver.SSHV2),
     ]