Added support of bytearrays to msgpack/fallback.py
This commit is contained in:
@@ -193,6 +193,8 @@ class Unpacker(object):
|
||||
def feed(self, next_bytes):
|
||||
if isinstance(next_bytes, array.array):
|
||||
next_bytes = next_bytes.tostring()
|
||||
elif isinstance(next_bytes, bytearray):
|
||||
next_bytes = str(next_bytes)
|
||||
assert self._fb_feeding
|
||||
if self._fb_buf_n + len(next_bytes) > self._max_buffer_size:
|
||||
raise BufferFull
|
||||
|
||||
@@ -11,3 +11,10 @@ def test_unpack_buffer():
|
||||
obj = unpackb(buf, use_list=1)
|
||||
assert [b'foo', b'bar'] == obj
|
||||
|
||||
|
||||
def test_unpack_bytearray():
|
||||
buf = bytearray(packb(('foo', 'bar')))
|
||||
obj = unpackb(buf, use_list=1)
|
||||
assert [b'foo', b'bar'] == obj
|
||||
assert all(type(s)==str for s in obj)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user