Mercurial > public > mercurial-scm > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
41383:0cfbe78fc13e | 41384:b141b5243b37 |
---|---|
787 if self.logdataapis: | 787 if self.logdataapis: |
788 self.fh.write('%s> readinto(%d) -> %r' % (self.name, len(dest), | 788 self.fh.write('%s> readinto(%d) -> %r' % (self.name, len(dest), |
789 res)) | 789 res)) |
790 | 790 |
791 data = dest[0:res] if res is not None else b'' | 791 data = dest[0:res] if res is not None else b'' |
792 | |
793 # _writedata() uses "in" operator and is confused by memoryview because | |
794 # characters are ints on Python 3. | |
795 if isinstance(data, memoryview): | |
796 data = data.tobytes() | |
797 | |
792 self._writedata(data) | 798 self._writedata(data) |
793 | 799 |
794 def write(self, res, data): | 800 def write(self, res, data): |
795 if not self.writes: | 801 if not self.writes: |
796 return | 802 return |