Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def testDecodeBinary():
re = unpacks(packs("abc"), encoding=None)
assert_equal(re, b"abc")
def _check(obj):
# NOTE:
# msgpack.packs(obj) nad msgpack_pure.packs(obj) are not necessarily
# match because there are some possible variations which type to use
# for integer values (i.e. uint8/int16 for 0xFF).
obj = _list_to_tuple(obj)
assert msgpack_pure.unpacks(msgpack.packs(obj)) == obj
assert msgpack.unpacks(msgpack_pure.packs(obj)) == obj
assert msgpack_pure.unpacks(msgpack_pure.packs(obj)) == obj
def testPackUTF32():
test_data = [
"", "abcd", ("defgh",), "Русский текст",
]
for td in test_data:
re = unpacks(packs(td, encoding='utf-32'), encoding='utf-32')
assert_equal(re, td)
def test_decode_hook():
packed = packs([3, {b'__complex__': True, b'real': 1, b'imag': 2}])
unpacked = unpacks(packed, object_hook=_decode_complex)
eq_(unpacked[1], 1+2j)
def test_array_hook():
packed = packs([1,2,3])
unpacked = unpacks(packed, list_hook=_arr_to_str)
eq_(unpacked, '123')
def match(obj, buf):
assert_equal(packs(obj), buf)
assert_equal(unpacks(buf), obj)
def check(length, obj):
v = packs(obj)
assert_equal(len(v), length, "%r length should be %r but get %r" % (obj, length, len(v)))
assert_equal(unpacks(v), obj)
def register_msgpack():
"""See http://msgpack.sourceforge.net/"""
try:
import msgpack
registry.register('msgpack', msgpack.packs, msgpack.unpacks,
content_type='application/x-msgpack',
content_encoding='binary')
except ImportError:
def not_available(*args, **kwargs):
"""In case a client receives a msgpack message, but yaml
isn't installed."""
raise SerializerNotInstalled(
"No decoder installed for msgpack. "
"Install the msgpack library")
registry.register('msgpack', None, not_available,
'application/x-msgpack')