diff options
author | jfolz <theriddling@gmail.com> | 2017-05-18 13:03:15 +0200 |
---|---|---|
committer | INADA Naoki <methane@users.noreply.github.com> | 2017-05-18 20:03:15 +0900 |
commit | f0f2c0b39703e0129d2352c71ec9811a8f275cc8 (patch) | |
tree | 927b079e6be25fe7db2e7108b75efdd1a79c1692 /msgpack/fallback.py | |
parent | a8d9162ca6cff6101c1f6b9547e94749c6acae96 (diff) | |
download | msgpack-python-f0f2c0b39703e0129d2352c71ec9811a8f275cc8.tar.gz |
Packer accepts bytearray objects (#229)
Diffstat (limited to 'msgpack/fallback.py')
-rw-r--r-- | msgpack/fallback.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/msgpack/fallback.py b/msgpack/fallback.py index 508fd06..a02cbe1 100644 --- a/msgpack/fallback.py +++ b/msgpack/fallback.py @@ -38,6 +38,8 @@ if hasattr(sys, 'pypy_version_info'): def write(self, s): if isinstance(s, memoryview): s = s.tobytes() + elif isinstance(s, bytearray): + s = bytes(s) self.builder.append(s) def getvalue(self): return self.builder.build() @@ -728,10 +730,10 @@ class Packer(object): default_used = True continue raise PackOverflowError("Integer value out of range") - if check(obj, bytes): + if check(obj, (bytes, bytearray)): n = len(obj) if n >= 2**32: - raise PackValueError("Bytes is too large") + raise PackValueError("%s is too large" % type(obj).__name__) self._pack_bin_header(n) return self._buffer.write(obj) if check(obj, Unicode): |