Skip to content
Snippets Groups Projects
Commit 7f631254 authored by KERDREUX Jerome's avatar KERDREUX Jerome
Browse files

Format

parent d126e837
Branches
No related tags found
1 merge request!1First try of type hints
......@@ -16,6 +16,7 @@ def tag_hook(decoder, tag, shareable_index=None):
return bindings.URL(tag.value)
return tag
def default_encoder(encoder, value):
if isinstance(value, bindings.UUID):
encoder.encode(CBORTag(37, value.bytes))
......@@ -23,17 +24,21 @@ def default_encoder(encoder, value):
if isinstance(value, bindings.URL):
encoder.encode(CBORTag(32, value.bytes))
def dumps(obj, **kwargs):
return cbor2.dumps(obj, default=default_encoder, **kwargs)
def loads(payload, **kwargs):
# return cbor2.loads(payload,tag_hook=tag_hook,**kwargs)
return _loads(payload, tag_hook=tag_hook, **kwargs)
def _loads(s, **kwargs):
with BytesIO(s) as fp:
return CBORDecoder(fp, **kwargs).decode()
# class CustomDecoder(CBORDecoder):pass
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment