cbor_py
cbor_py copied to clipboard
Tagged types can not be nested
Tagged types using cbor.TagMapper()
can not be nested:
#!/usr/bin/env python3
import cbor
from collections import namedtuple
test = namedtuple('test', 'x y')
cbor_test = cbor.ClassTag(15309737, test, tuple, lambda x: test(*x))
cbor_set = cbor.ClassTag(15309738, set, tuple, lambda x: set(x))
mapper = cbor.TagMapper(class_tags=(cbor_test, cbor_set),
raise_on_unknown_tag=True)
x = {7:test(1,{1,2,3})}
y = mapper.loads(mapper.dumps(x))
print(y == x)
Traceback (most recent call last):
File "./z.py", line 13, in <module>
y = mapper.loads(mapper.dumps(x))
File "/usr/local/lib/python3.6/site-packages/cbor/tagmap.py", line 99, in dumps
return dumps(self.encode(obj))
ValueError: cannot serialize unknown object: {1, 2, 3}
I have a patch for this. Should I do a pull request here or in BitBucket?