Skip to content
Snippets Groups Projects
Commit 83db57b8 authored by jkerdreu's avatar jkerdreu
Browse files

Added Cbor tags for URL.

This gonna change soon, as it requires a cbor2 patch

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/branches/0.7@2443 b32b6428-25c9-4566-ad07-03861ab6144f
parent a02fb8da
Branches
No related tags found
No related merge requests found
......@@ -37,3 +37,6 @@ class UUID(uuid.UUID):
def str(self):
return str(self)
class URL(str):pass
......@@ -10,12 +10,16 @@ cbor2.decoder.semantic_decoders.pop(37)
def tag_hook(decoder, tag, shareable_index=None):
if tag.tag == 37:
return bindings.UUID(bytes=tag.value)
if tag.tag == 32:
return bindings.URL(tag.value)
return tag
def default_encoder(encoder, value):
if type(value) == bindings.UUID:
encoder.encode(CBORTag(37, value.bytes))
if type(value) == bindings.URL:
encoder.encode(CBORTag(32, str(value)))
def dumps(obj, **kwargs):
return cbor2.dumps(obj,default=default_encoder,**kwargs)
......
......@@ -23,6 +23,7 @@
from . import config
from . import tools
from . import bindings
from .exceptions import DeviceError
import logging
......@@ -56,7 +57,8 @@ class Attribute(object):
class Attributes(list):
"""Devices owns a attributes list. This list also have dict-like access"""
def __getitem__(self,value):
if isinstance(value,int):
return list.__getitem__(self,value)
......@@ -137,6 +139,17 @@ class Device(object):
raise DeviceError("This address is not valid")
self.__address = value
@property
def url(self):
return self.__url
@url.setter
def url(self,value):
if value == None:
self.__url = None
else:
self.__url = bindings.URL(value)
# attributes
def new_attribute(self,name,default=None):
attr = Attribute(name,self,default)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment