本文整理汇总了Python中coapthon.messages.request.Request.observe方法的典型用法代码示例。如果您正苦于以下问题:Python Request.observe方法的具体用法?Python Request.observe怎么用?Python Request.observe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类coapthon.messages.request.Request
的用法示例。
在下文中一共展示了Request.observe方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_td_coap_obs_01
# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import observe [as 别名]
def test_td_coap_obs_01(self):
print "TD_COAP_OBS_01"
path = "/obs"
req = Request()
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
req.observe = 0
expected = Response()
expected.type = defines.inv_types["ACK"]
expected._mid = self.current_mid
expected.code = defines.responses["CONTENT"]
expected.token = None
expected.payload = "Observable Resource"
expected.observe = 1
expected2 = Response()
expected2.type = defines.inv_types["CON"]
expected2._mid = self.server_mid
expected2.code = defines.responses["CONTENT"]
expected2.token = None
expected2.payload = "Observable Resource"
expected2.observe = 2
self.current_mid += 1
self.server_mid += 1
self._test_plugtest([(req, expected), (None, expected2)])
示例2: observe
# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import observe [as 别名]
def observe(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]
assert(isinstance(req, Request))
path = req.uri_path
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['GET']
req.uri_path = path
req.observe = 0
req.type = defines.inv_types["CON"]
self.send_callback(req, self.observe_results, client_callback)
示例3: observe
# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import observe [as 别名]
def observe(self, path, callback): # pragma: no cover
request = Request()
request.destination = self.server
request.code = defines.Codes.GET.number
request.uri_path = path
request.observe = 0
if callback is not None:
thread = threading.Thread(target=self._thread_body, args=(request, callback))
thread.start()
else:
self.protocol.send_message(request)
response = self.queue.get(block=True)
return response
示例4: observe
# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import observe [as 别名]
def observe(self, client_callback, *args, **kwargs):
path = args[0]
req = Request()
if "Token" in kwargs.keys():
req.token = kwargs.get("Token")
del kwargs["Token"]
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.observe = 0
req.type = defines.inv_types["CON"]
self.send_callback(req, self.observe_results, client_callback)
示例5: test_td_coap_obs_03
# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import observe [as 别名]
def test_td_coap_obs_03(self):
print "TD_COAP_OBS_03"
path = "/obs"
req = Request()
req.code = defines.Codes.GET.number
req.uri_path = path
req.type = defines.Types["CON"]
req._mid = self.current_mid
req.destination = self.server_address
req.observe = 0
expected = Response()
expected.type = defines.Types["ACK"]
expected._mid = self.current_mid
expected.code = defines.Codes.CONTENT.number
expected.token = None
expected.payload = "Observable Resource"
expected.observe = 1
self.current_mid += 1
expected2 = Response()
expected2.type = defines.Types["CON"]
expected2._mid = self.server_mid
expected2.code = defines.Codes.CONTENT.number
expected2.token = None
expected2.payload = "Observable Resource"
expected2.observe = 1
rst = Response()
rst.type = defines.Types["RST"]
rst._mid = self.server_mid
rst.code = defines.Codes.EMPTY.number
rst.destination = self.server_address
rst.token = None
rst.payload = None
self.current_mid += 1
self.server_mid += 1
self._test_plugtest([(req, expected), (None, expected2), (rst, None)])
示例6: observe
# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import observe [as 别名]
def observe(self, *args, **kwargs):
"""
:param args: request object
:param kwargs: dictionary with parameters
"""
if len(args) > 0:
request = args[0]
assert isinstance(request, Request)
endpoint = request.destination
else:
request = Request()
path = kwargs["path"]
assert isinstance(path, str)
ip, port, path = self.parse_path(path)
request.destination = (ip, port)
request.uri_path = path
endpoint = (ip, port)
request.code = defines.inv_codes["GET"]
request.observe = 0
self.send(request, endpoint)