FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fallback: return available bytes on short feed-based reads by zhechen-cs · Pull Request #752 · msgpack/msgpack-python · GitHub

Repository navigation

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
6 changes: 4 additions & 2 deletions msgpack/fallback.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,10 @@ def _reserve(self, n, raise_outofdata=True):
return

if self._feeding:
self._buff_i = self._buf_checkpoint
raise OutOfData
if raise_outofdata:
self._buff_i = self._buf_checkpoint
raise OutOfData
return

# Strip buffer before checkpoint before reading file.
if self._buf_checkpoint > 0:
Expand Down
17 changes: 16 additions & 1 deletion test/test_sequnpack.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
import io

from pytest import raises
from pytest import mark, raises

from msgpack import BufferFull, Unpacker, pack, packb
from msgpack.exceptions import OutOfData
Expand Down Expand Up @@ -169,3 +169,18 @@ def test_unpack_tell():
m2 = next(unpacker)
assert m == m2
assert o == unpacker.tell()


@mark.parametrize("data", [b"", b"ab"])
def test_readbytes_short_feed(data):
unpacker = Unpacker()
unpacker.feed(packb(42) + data)
assert unpacker.unpack() == 42
assert unpacker.read_bytes(5) == data
assert unpacker.tell() == 1 + len(data)
assert unpacker.read_bytes(5) == b""
assert unpacker.tell() == 1 + len(data)

unpacker.feed(packb("next"))
assert unpacker.unpack() == "next"
assert unpacker.tell() == 1 + len(data) + len(packb("next"))
Loading

Back | FazBrowse Home | New Git URL