Support object_pairs_hook

Merge remote-tracking branch 'jnothman/object_pairs_hook' into 0.2-maint
Conflicts:
	msgpack/_msgpack.pyx
	test/test_pack.py
	test/test_sequnpack.py
This commit is contained in:
INADA Naoki 2012-09-24 03:05:39 +09:00
commit e381032641
7 changed files with 143 additions and 90 deletions

View file

@ -26,6 +26,16 @@ def test_decode_hook():
unpacked = unpackb(packed, object_hook=_decode_complex, use_list=1)
eq_(unpacked[1], 1+2j)
def test_decode_pairs_hook():
packed = packb([3, {1: 2, 3: 4}])
prod_sum = 1 * 2 + 3 * 4
unpacked = unpackb(packed, object_pairs_hook=lambda l: sum(k * v for k, v in l))
eq_(unpacked[1], prod_sum)
@raises(ValueError)
def test_only_one_obj_hook():
unpackb(b'', object_hook=lambda x: x, object_pairs_hook=lambda x: x)
@raises(ValueError)
def test_bad_hook():
packed = packb([3, 1+2j], default=lambda o: o)