summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Zhuravlev <zhurs@ya.ru>2013-12-15 16:22:39 +0000
committerSergey Zhuravlev <zhurs@ya.ru>2013-12-15 16:22:39 +0000
commit48ca2d700d019bfec9abe3242a8eb3073c803951 (patch)
tree8918dd549396233357b05fb58abdb283c9b492ee
parentd5436c28197f3ccdd473e1c54838133574948dab (diff)
downloadmsgpack-python-48ca2d700d019bfec9abe3242a8eb3073c803951.tar.gz
Added support of bytearrays to msgpack/fallback.py
-rw-r--r--msgpack/fallback.py2
-rw-r--r--test/test_buffer.py7
2 files changed, 9 insertions, 0 deletions
diff --git a/msgpack/fallback.py b/msgpack/fallback.py
index bf5b1c2..3ef1341 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 = str(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..5ae87ac 100644
--- a/test/test_buffer.py
+++ b/test/test_buffer.py
@@ -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)
+