# HG changeset patch # User Gregory Szorc # Date 2019-01-26 00:00:34 # Node ID b141b5243b37053c57c432417a80728758b2044d # Parent 0cfbe78fc13ed10d8f833d0b43c6e1c86cd696a9 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 diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -789,6 +789,12 @@ class fileobjectobserver(baseproxyobserv 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):