summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--msgpack/fallback.py2
-rw-r--r--test/test_buffer.py10
2 files changed, 11 insertions, 1 deletions
diff --git a/msgpack/fallback.py b/msgpack/fallback.py
index cf61023..55de72c 100644
--- a/msgpack/fallback.py
+++ b/msgpack/fallback.py
@@ -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 = bytes(next_bytes)
assert self._fb_feeding
if self._fb_buf_n + len(next_bytes) > self._max_buffer_size:
raise BufferFull
diff --git a/test/test_buffer.py b/test/test_buffer.py
index 04cc02d..6cb2295 100644
--- a/test/test_buffer.py
+++ b/test/test_buffer.py
@@ -2,12 +2,20 @@
# coding: utf-8
from msgpack import packb, unpackb
+import sys
def test_unpack_buffer():
from array import array
buf = array('b')
- buf.fromstring(packb(('foo', 'bar')))
+ buf.fromstring(packb((b'foo', b'bar')))
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
+ expected_type = bytes
+ assert all(type(s) == expected_type for s in obj)