diff --git a/libs/lib/xaal/lib/cbor.py b/libs/lib/xaal/lib/cbor.py index cf2d622d676087337d8e68a3189b9a176d3960b0..991c3cbac93f9644cdb77cf5fa0cacab039ddf86 100644 --- a/libs/lib/xaal/lib/cbor.py +++ b/libs/lib/xaal/lib/cbor.py @@ -16,25 +16,30 @@ 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): + if isinstance(value, bindings.UUID): encoder.encode(CBORTag(37, value.bytes)) - if isinstance(value,bindings.URL): + if isinstance(value, bindings.URL): encoder.encode(CBORTag(32, value.bytes)) + def dumps(obj, **kwargs): - return cbor2.dumps(obj,default=default_encoder,**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) + # 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 + +# class CustomDecoder(CBORDecoder):pass def cleanup(obj): @@ -45,14 +50,14 @@ def cleanup(obj): Warning: This operate in-place changes. Warning: This won't work for tags in dict keys. """ - if isinstance(obj,list): - for i in range(0,len(obj)): + if isinstance(obj, list): + for i in range(0, len(obj)): obj[i] = cleanup(obj[i]) return obj - if isinstance(obj,dict): + if isinstance(obj, dict): for k in obj.keys(): - obj.update({k:cleanup(obj[k])}) + obj.update({k: cleanup(obj[k])}) return obj if type(obj) in bindings.classes: