Skip to content

Commit

Permalink
add support for bytearray type in loads/unpackb for python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
vsergeev committed Sep 25, 2016
1 parent 6859c81 commit 201ea17
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions umsgpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,8 +736,6 @@ def _unpackb2(s):
Example:
>>> umsgpack.unpackb(b'\x82\xa7compact\xc3\xa6schema\x00')
{u'compact': True, u'schema': 0}
>>> umsgpack.unpackb(bytearray(b'\x82\xa7compact\xc3\xa6schema\x00'))
{u'compact': True, u'schema': 0}
>>>
"""
if not isinstance(s, (str, bytearray)):
Expand All @@ -750,14 +748,14 @@ def _unpackb3(s):
Deserialize MessagePack bytes into a Python object.
Args:
s: a 'bytes' containing serialized MessagePack bytes
s: a 'bytes' or 'bytearray' containing serialized MessagePack bytes
Returns:
A Python object.
Raises:
TypeError:
Packed data is not type 'bytes'.
Packed data type is neither 'bytes' nor 'bytearray'.
InsufficientDataException(UnpackException):
Insufficient data to unpack the encoded object.
InvalidStringException(UnpackException):
Expand All @@ -775,8 +773,8 @@ def _unpackb3(s):
{'compact': True, 'schema': 0}
>>>
"""
if not isinstance(s, bytes):
raise TypeError("packed data is not type 'bytes'")
if not isinstance(s, (bytes, bytearray)):
raise TypeError("packed data must be type 'bytes' or 'bytearray'")
return _unpack(io.BytesIO(s))

################################################################################
Expand Down

0 comments on commit 201ea17

Please sign in to comment.