mirror of
https://github.com/msgpack/msgpack-python.git
synced 2025-10-22 21:33:17 +00:00
Add raw_as_bytes option to Unpacker. (#265)
This commit is contained in:
parent
50ea49c86f
commit
5534d0c7af
11 changed files with 199 additions and 93 deletions
|
@ -47,8 +47,8 @@ def test_unpacker_ext_hook():
|
|||
class MyUnpacker(Unpacker):
|
||||
|
||||
def __init__(self):
|
||||
super(MyUnpacker, self).__init__(ext_hook=self._hook,
|
||||
encoding='utf-8')
|
||||
super(MyUnpacker, self).__init__(
|
||||
ext_hook=self._hook, raw_as_bytes=False)
|
||||
|
||||
def _hook(self, code, data):
|
||||
if code == 1:
|
||||
|
@ -57,11 +57,11 @@ def test_unpacker_ext_hook():
|
|||
return ExtType(code, data)
|
||||
|
||||
unpacker = MyUnpacker()
|
||||
unpacker.feed(packb({'a': 1}, encoding='utf-8'))
|
||||
unpacker.feed(packb({'a': 1}))
|
||||
assert unpacker.unpack() == {'a': 1}
|
||||
unpacker.feed(packb({'a': ExtType(1, b'123')}, encoding='utf-8'))
|
||||
unpacker.feed(packb({'a': ExtType(1, b'123')}))
|
||||
assert unpacker.unpack() == {'a': 123}
|
||||
unpacker.feed(packb({'a': ExtType(2, b'321')}, encoding='utf-8'))
|
||||
unpacker.feed(packb({'a': ExtType(2, b'321')}))
|
||||
assert unpacker.unpack() == {'a': ExtType(2, b'321')}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue