From 48ca2d700d019bfec9abe3242a8eb3073c803951 Mon Sep 17 00:00:00 2001 From: Sergey Zhuravlev Date: Sun, 15 Dec 2013 16:22:39 +0000 Subject: Added support of bytearrays to msgpack/fallback.py --- msgpack/fallback.py | 2 ++ test/test_buffer.py | 7 +++++++ 2 files changed, 9 insertions(+) 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) + -- cgit v1.2.1