Fix fallback Unpacker.read() (#388)

Fixes #352.
This commit is contained in:
Inada Naoki 2019-12-06 21:16:27 +09:00 committed by GitHub
parent 7a8ce0f9ca
commit f6f6f328eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View file

@ -357,7 +357,9 @@ class Unpacker(object):
return self._buffer[self._buff_i :]
def read_bytes(self, n):
return self._read(n)
ret = self._read(n)
self._consume()
return ret
def _read(self, n):
# (int) -> bytearray

View file

@ -93,6 +93,15 @@ def test_readbytes():
assert unpacker.unpack() == ord(b"a")
assert unpacker.unpack() == ord(b"r")
# Issue 352
u = Unpacker()
u.feed(b"x")
assert bytes(u.read_bytes(1)) == b"x"
with raises(StopIteration):
next(u)
u.feed(b"\1")
assert next(u) == 1
def test_issue124():
unpacker = Unpacker()