mirror of
https://github.com/msgpack/msgpack-python.git
synced 2025-10-19 20:03:16 +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
|
@ -31,14 +31,14 @@ def testPack():
|
|||
def testPackUnicode():
|
||||
test_data = ["", "abcd", ["defgh"], "Русский текст"]
|
||||
for td in test_data:
|
||||
re = unpackb(packb(td, encoding='utf-8'), use_list=1, encoding='utf-8')
|
||||
re = unpackb(packb(td), use_list=1, raw_as_bytes=False)
|
||||
assert re == td
|
||||
packer = Packer(encoding='utf-8')
|
||||
packer = Packer()
|
||||
data = packer.pack(td)
|
||||
re = Unpacker(BytesIO(data), encoding=str('utf-8'), use_list=1).unpack()
|
||||
re = Unpacker(BytesIO(data), raw_as_bytes=False, use_list=1).unpack()
|
||||
assert re == td
|
||||
|
||||
def testPackUTF32():
|
||||
def testPackUTF32(): # deprecated
|
||||
try:
|
||||
test_data = [
|
||||
"",
|
||||
|
@ -66,26 +66,22 @@ def testPackByteArrays():
|
|||
for td in test_data:
|
||||
check(td)
|
||||
|
||||
def testIgnoreUnicodeErrors():
|
||||
def testIgnoreUnicodeErrors(): # deprecated
|
||||
re = unpackb(packb(b'abc\xeddef'), encoding='utf-8', unicode_errors='ignore', use_list=1)
|
||||
assert re == "abcdef"
|
||||
|
||||
def testStrictUnicodeUnpack():
|
||||
with raises(UnicodeDecodeError):
|
||||
unpackb(packb(b'abc\xeddef'), encoding='utf-8', use_list=1)
|
||||
unpackb(packb(b'abc\xeddef'), raw_as_bytes=False, use_list=1)
|
||||
|
||||
def testStrictUnicodePack():
|
||||
def testStrictUnicodePack(): # deprecated
|
||||
with raises(UnicodeEncodeError):
|
||||
packb("abc\xeddef", encoding='ascii', unicode_errors='strict')
|
||||
|
||||
def testIgnoreErrorsPack():
|
||||
re = unpackb(packb("abcФФФdef", encoding='ascii', unicode_errors='ignore'), encoding='utf-8', use_list=1)
|
||||
def testIgnoreErrorsPack(): # deprecated
|
||||
re = unpackb(packb("abcФФФdef", encoding='ascii', unicode_errors='ignore'), raw_as_bytes=False, use_list=1)
|
||||
assert re == "abcdef"
|
||||
|
||||
def testNoEncoding():
|
||||
with raises(TypeError):
|
||||
packb("abc", encoding=None)
|
||||
|
||||
def testDecodeBinary():
|
||||
re = unpackb(packb(b"abc"), encoding=None, use_list=1)
|
||||
assert re == b"abc"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue