本文整理汇总了Python中coapthon.messages.option.Option.number方法的典型用法代码示例。如果您正苦于以下问题:Python Option.number方法的具体用法?Python Option.number怎么用?Python Option.number使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类coapthon.messages.option.Option
的用法示例。
在下文中一共展示了Option.number方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_td_coap_core_06
# 需要导入模块: from coapthon.messages.option import Option [as 别名]
# 或者: from coapthon.messages.option.Option import number [as 别名]
def test_td_coap_core_06(self):
print "TD_COAP_CORE_06"
path = "/test_post"
req = Request()
req.code = defines.inv_codes['POST']
req.uri_path = path
req.type = defines.inv_types["NON"]
o = Option()
o.number = defines.inv_options["Content-Type"]
o.value = defines.inv_content_types["application/xml"]
req.add_option(o)
req._mid = self.current_mid
req.destination = self.server_address
req.payload = "<value>test</value>"
expected = Response()
expected.type = defines.inv_types["NON"]
expected._mid = None
expected.code = defines.responses["CREATED"]
expected.token = None
expected.payload = None
option = Option()
option.number = defines.inv_options["Location-Path"]
option.value = "/test_post"
expected.add_option(option)
self.current_mid += 1
self._test_plugtest(req, expected)
示例2: test_post_and_get_storage
# 需要导入模块: from coapthon.messages.option import Option [as 别名]
# 或者: from coapthon.messages.option.Option import number [as 别名]
def test_post_and_get_storage(self):
print "\nPOST /storage/data1 - GET /storage/data1\n"
args = ("/storage/data1",)
kwargs = {}
path = args[0]
req = Request()
for key in kwargs:
o = Option()
o.number = defines.inv_options[key]
o.value = kwargs[key]
req.add_option(o)
req.code = defines.inv_codes['POST']
req.uri_path = path
req.type = defines.inv_types["CON"]
req._mid = self.current_mid
req.payload = "Created"
req.destination = self.server_address
expected = Response()
expected.type = defines.inv_types["ACK"]
expected._mid = self.current_mid
expected.code = defines.responses["CREATED"]
expected.token = None
expected.payload = None
option = Option()
option.number = defines.inv_options["Location-Path"]
option.value = "/storage/data1"
expected.add_option(option)
self.current_mid += 1
self._test(req, expected)
req = Request()
for key in kwargs:
o = Option()
o.number = defines.inv_options[key]
o.value = kwargs[key]
req.add_option(o)
req.code = defines.inv_codes['GET']
req.uri_path = path
req.type = defines.inv_types["CON"]
req._mid = self.current_mid
req.destination = self.server_address
expected = Response()
expected.type = defines.inv_types["ACK"]
expected._mid = self.current_mid
expected.code = defines.responses["CONTENT"]
expected.token = None
expected.payload = "Created"
self.current_mid += 1
self._test(req, expected)
示例3: block2
# 需要导入模块: from coapthon.messages.option import Option [as 别名]
# 或者: from coapthon.messages.option.Option import number [as 别名]
def block2(self, value):
"""
Set the Block2 option.
:param value: the Block2 value, (num, m, size)
"""
option = Option()
option.number = defines.inv_options['Block2']
num, m, size = value
if size > 1024:
szx = 6
elif 512 < size <= 1024:
szx = 6
elif 256 < size <= 512:
szx = 5
elif 128 < size <= 256:
szx = 4
elif 64 < size <= 128:
szx = 3
elif 32 < size <= 64:
szx = 2
elif 16 < size <= 32:
szx = 1
else:
szx = 0
value = (num << 4)
value |= (m << 3)
value |= szx
option.value = value
self.add_option(option)
示例4: if_match
# 需要导入模块: from coapthon.messages.option import Option [as 别名]
# 或者: from coapthon.messages.option.Option import number [as 别名]
def if_match(self, values):
assert isinstance(values, list)
for v in values:
option = Option()
option.number = defines.OptionRegistry.IF_MATCH.number
option.value = v
self.add_option(option)
示例5: test_get_not_found
# 需要导入模块: from coapthon.messages.option import Option [as 别名]
# 或者: from coapthon.messages.option.Option import number [as 别名]
def test_get_not_found(self):
print "\nGET /not_found\n"
args = ("/not_found",)
kwargs = {}
path = args[0]
req = Request()
for key in kwargs:
o = Option()
o.number = defines.inv_options[key]
o.value = kwargs[key]
req.add_option(o)
req.code = defines.inv_codes['GET']
req.uri_path = path
req.type = defines.inv_types["CON"]
req._mid = self.current_mid
req.destination = self.server_address
expected = Response()
expected.type = defines.inv_types["ACK"]
expected._mid = self.current_mid
expected.code = defines.responses["NOT_FOUND"]
expected.token = None
expected.payload = None
self.current_mid += 1
self._test(req, expected)
示例6: add_observing
# 需要导入模块: from coapthon.messages.option import Option [as 别名]
# 或者: from coapthon.messages.option.Option import number [as 别名]
def add_observing(self, resource, request, response):
"""
Add an observer to a resource and sets the Observe option in the response.
:param resource: the resource of interest
:param request: the request
:param response: the response
:return: response
"""
host, port = response.destination
key = hash(str(host) + str(port) + str(response.token))
observers = self._parent.relation.get(resource)
now = int(round(time.time() * 1000))
observe_count = resource.observe_count
if observers is None:
# log.msg("Initiate an observe relation between " + str(host) + ":" +
# str(port) + " and resource " + str(resource.path))
observers = {key: (now, request, response)}
elif key not in observers:
# log.msg("Initiate an observe relation between " + str(host) + ":" +
# str(port) + " and resource " + str(resource.path))
observers[key] = (now, request, response)
else:
# log.msg("Update observe relation between " + str(host) + ":" +
# str(port) + " and resource " + str(resource.path))
old, request, response = observers[key]
observers[key] = (now, request, response)
self._parent.relation[resource] = observers
option = Option()
option.number = defines.inv_options['Observe']
option.value = observe_count
response.add_option(option)
return response
示例7: test_get_separate
# 需要导入模块: from coapthon.messages.option import Option [as 别名]
# 或者: from coapthon.messages.option.Option import number [as 别名]
def test_get_separate(self):
print "\nGET /separate\n"
args = ("/separate",)
kwargs = {}
path = args[0]
req = Request()
for key in kwargs:
o = Option()
o.number = defines.inv_options[key]
o.value = kwargs[key]
req.add_option(o)
req.code = defines.inv_codes['GET']
req.uri_path = path
req.type = defines.inv_types["CON"]
req._mid = self.current_mid
req.destination = self.server_address
expected = Response()
expected.type = defines.inv_types["CON"]
expected.code = defines.responses["CONTENT"]
expected.token = None
expected.payload = "Separate"
self.current_mid += 1
self._test_separate(req, expected)
示例8: delete
# 需要导入模块: from coapthon.messages.option import Option [as 别名]
# 或者: from coapthon.messages.option.Option import number [as 别名]
def delete(self, client_callback, *args, **kwargs):
if isinstance(args[0], str):
path = str(args[0])
req = Request()
req.uri_path = path
if "Token" in kwargs.keys():
req.token = kwargs.get("Token")
del kwargs["Token"]
if "MID" in kwargs.keys():
req.mid = kwargs.get("MID")
del kwargs["MID"]
if "Server" in kwargs.keys():
req.destination = kwargs.get("Server")
del kwargs["Server"]
else:
req = args[0]
for key in kwargs:
try:
o = Option()
o.number = defines.inv_options[key]
o.value = kwargs[key]
req.add_option(o)
except KeyError:
pass
req.code = defines.inv_codes['DELETE']
req.type = defines.inv_types["CON"]
self.send_callback(req, self.delete_results, client_callback)
示例9: add_block2
# 需要导入模块: from coapthon.messages.option import Option [as 别名]
# 或者: from coapthon.messages.option.Option import number [as 别名]
def add_block2(self, num, m, size):
"""
Add and format a Block2 option to a request.
:param num: num
:param m: more blocks
:param size: size in byte
"""
option = Option()
option.number = defines.inv_options['Block2']
if size > 1024:
szx = 6
elif 512 < size <= 1024:
szx = 6
elif 256 < size <= 512:
szx = 5
elif 128 < size <= 256:
szx = 4
elif 64 < size <= 128:
szx = 3
elif 32 < size <= 64:
szx = 2
elif 16 < size <= 32:
szx = 1
else:
szx = 0
value = (num << 4)
value |= (m << 3)
value |= szx
option.value = value
self.add_option(option)
示例10: test_long
# 需要导入模块: from coapthon.messages.option import Option [as 别名]
# 或者: from coapthon.messages.option.Option import number [as 别名]
def test_long(self):
print "\nGET /long\n"
args = ("/long",)
kwargs = {}
path = args[0]
req = Request()
for key in kwargs:
o = Option()
o.number = defines.inv_options[key]
o.value = kwargs[key]
req.add_option(o)
req.code = defines.inv_codes['GET']
req.uri_path = path
req.type = defines.inv_types["CON"]
req._mid = self.current_mid
req.destination = self.server_address
expected = Response()
expected.type = defines.inv_types["ACK"]
expected._mid = self.current_mid
expected.code = None
expected.token = None
expected.payload = None
expected2 = Response()
expected2.type = defines.inv_types["CON"]
expected2.code = defines.responses["CONTENT"]
expected2.token = None
expected2.payload = "Long Time"
self.current_mid += 1
self._test_modular([(req, expected), (None, expected2)])
示例11: block2
# 需要导入模块: from coapthon.messages.option import Option [as 别名]
# 或者: from coapthon.messages.option.Option import number [as 别名]
def block2(self, value):
option = Option()
option.number = defines.OptionRegistry.BLOCK2.number
num, m, size = value
if size > 1024:
szx = 6
elif 512 < size <= 1024:
szx = 6
elif 256 < size <= 512:
szx = 5
elif 128 < size <= 256:
szx = 4
elif 64 < size <= 128:
szx = 3
elif 32 < size <= 64:
szx = 2
elif 16 < size <= 32:
szx = 1
else:
szx = 0
value = (num << 4)
value |= (m << 3)
value |= szx
option.value = value
self.add_option(option)
示例12: add_if_none_match
# 需要导入模块: from coapthon.messages.option import Option [as 别名]
# 或者: from coapthon.messages.option.Option import number [as 别名]
def add_if_none_match(self):
"""
Add the if-none-match option to the request.
"""
option = Option()
option.number = defines.OptionRegistry.IF_NONE_MATCH.number
option.value = None
self.add_option(option)
示例13: location_query
# 需要导入模块: from coapthon.messages.option import Option [as 别名]
# 或者: from coapthon.messages.option.Option import number [as 别名]
def location_query(self, value):
del self.location_query
queries = value.split("&")
for q in queries:
option = Option()
option.number = defines.OptionRegistry.LOCATION_QUERY.number
option.value = str(q)
self.add_option(option)
示例14: block1
# 需要导入模块: from coapthon.messages.option import Option [as 别名]
# 或者: from coapthon.messages.option.Option import number [as 别名]
def block1(self, value):
option = Option()
option.number = defines.inv_options["Block1"]
num, m, size = value
value = num << 4
value |= m << 3
value |= size
option.value = value
示例15: proxy_uri
# 需要导入模块: from coapthon.messages.option import Option [as 别名]
# 或者: from coapthon.messages.option.Option import number [as 别名]
def proxy_uri(self, uri):
"""
Set the Proxy-Uri option of a request.
:param uri: the Proxy-Uri values
"""
option = Option()
option.number = defines.inv_options['Proxy-Uri']
option.value = str(uri)
self.add_option(option)