Mercurial > hg
diff mercurial/util.py @ 41384:b141b5243b37
util: cast memoryview to bytes
Python 3 uses readinto() instead of read() in places. And
taking a slice of the buffer passed to readinto() will produce
a memoryview. _writedata() then gets confused when testing for
`b'\n' in data` because memoryview is an iterable over ints
instead of 1 character bytes.
We work around by casting a memoryview to bytes.
Differential Revision: https://phab.mercurial-scm.org/D5704
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Fri, 25 Jan 2019 16:00:34 -0800 |
parents | 593f6359681d |
children | ae189674bdad |
line wrap: on
line diff
--- a/mercurial/util.py Fri Jan 25 15:36:55 2019 -0800 +++ b/mercurial/util.py Fri Jan 25 16:00:34 2019 -0800 @@ -789,6 +789,12 @@ res)) data = dest[0:res] if res is not None else b'' + + # _writedata() uses "in" operator and is confused by memoryview because + # characters are ints on Python 3. + if isinstance(data, memoryview): + data = data.tobytes() + self._writedata(data) def write(self, res, data):