mirror of
https://github.com/msgpack/msgpack-python.git
synced 2026-02-07 02:09:59 +00:00
python: Support old buffer protocol when unpack. (experimental)
This commit is contained in:
parent
b1df5d3ad7
commit
4688252bd4
3 changed files with 65 additions and 113 deletions
|
|
@ -7,10 +7,10 @@ from msgpack import packb, unpackb
|
|||
|
||||
def test_unpack_buffer():
|
||||
from array import array
|
||||
buf = array('b')
|
||||
buf.fromstring(packb(['foo', 'bar']))
|
||||
buf = array('c')
|
||||
buf.fromstring(packb(('foo', 'bar')))
|
||||
obj = unpackb(buf)
|
||||
assert_equal(['foo', 'bar'], obj)
|
||||
assert_equal(('foo', 'bar'), obj)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
|||
|
|
@ -1,22 +1,22 @@
|
|||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
from __future__ import unicode_literals, print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from msgpack import Unpacker
|
||||
|
||||
def test_foobar():
|
||||
unpacker = Unpacker(read_size=3)
|
||||
unpacker.feed(b'foobar')
|
||||
assert unpacker.unpack() == ord('f')
|
||||
assert unpacker.unpack() == ord('o')
|
||||
assert unpacker.unpack() == ord('o')
|
||||
assert unpacker.unpack() == ord('b')
|
||||
assert unpacker.unpack() == ord('a')
|
||||
assert unpacker.unpack() == ord('r')
|
||||
assert unpacker.unpack() == ord(b'f')
|
||||
assert unpacker.unpack() == ord(b'o')
|
||||
assert unpacker.unpack() == ord(b'o')
|
||||
assert unpacker.unpack() == ord(b'b')
|
||||
assert unpacker.unpack() == ord(b'a')
|
||||
assert unpacker.unpack() == ord(b'r')
|
||||
try:
|
||||
o = unpacker.unpack()
|
||||
print("Oops!", o)
|
||||
print "Oops!", o
|
||||
assert 0
|
||||
except StopIteration:
|
||||
assert 1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue