本文整理汇总了Python中coapthon.messages.request.Request.token方法的典型用法代码示例。如果您正苦于以下问题:Python Request.token方法的具体用法?Python Request.token怎么用?Python Request.token使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类coapthon.messages.request.Request
的用法示例。
在下文中一共展示了Request.token方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete
# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import token [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)
示例2: discover
# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import token [as 别名]
def discover(self, client_callback, *args, **kwargs):
req = Request()
if "Token" in kwargs.keys():
req.token = kwargs.get("Token")
req.code = defines.inv_codes['GET']
req.uri_path = ".well-known/core"
req.type = defines.inv_types["CON"]
self.send_callback(req, self.discover_results, client_callback)
示例3: post
# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import token [as 别名]
def post(self, path, payload, callback=None): # pragma: no cover
request = Request()
request.destination = self.server
request.code = defines.Codes.POST.number
request.token = generate_random_token(2)
request.uri_path = path
request.payload = payload
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: delete
# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import token [as 别名]
def delete(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['DELETE']
req.uri_path = path
req.type = defines.inv_types["CON"]
self.send_callback(req, self.delete_results, client_callback)
示例5: put
# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import token [as 别名]
def put(self, client_callback, *args, **kwargs):
path, payload = args
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['PUT']
req.uri_path = path
req.type = defines.inv_types["CON"]
req.payload = payload
self.send_callback(req, self.put_results, client_callback)
示例6: test_td_coap_core_10
# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import token [as 别名]
def test_td_coap_core_10(self):
print "TD_COAP_CORE_10"
path = "/test"
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.token = "ciao"
expected = Response()
expected.type = defines.inv_types["ACK"]
expected._mid = self.current_mid
expected.code = defines.responses["CONTENT"]
expected.token = None
expected.payload = "Test Resource"
expected.token = "ciao"
self.current_mid += 1
self._test_plugtest(req, expected)
示例7: forward_request
# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import token [as 别名]
def forward_request(self, request):
"""
Forward an incoming request to the specified server.
:param request: the request to be forwarded
:return: None if success, send an error otherwise
"""
# print "FORWARD REQUEST\n"
uri = request.proxy_uri
response = Response()
response.destination = request.source
token = self.generate_token()
if uri is None:
return self.send_error(request, response, "BAD_REQUEST")
host, port, path = self.parse_path(uri)
request.uri_path = path
self._currentMID += 1
method = defines.codes[request.code]
if method == 'GET':
function = self.client.protocol.get
req = Request()
req.destination = (str(host), int(port))
req.mid = self._currentMID % (1 << 16)
req.token = str(token)
req.uri_path = path
req.type = defines.inv_types["CON"]
req.code = defines.inv_codes['GET']
args = (req,)
kwargs = {}
callback = self.result_forward
err_callback = self.error
elif method == 'POST':
function = self.client.protocol.post
req = Request()
req.destination = (str(host), int(port))
req.mid = self._currentMID % (1 << 16)
req.token = str(token)
req.uri_path = path
req.payload = request.payload
req.type = defines.inv_types["CON"]
req.code = defines.inv_codes['POST']
args = (req,)
kwargs = {}
callback = self.result_forward
err_callback = self.error
elif method == 'PUT':
function = self.client.protocol.put
req = Request()
req.destination = (str(host), int(port))
req.mid = self._currentMID % (1 << 16)
req.token = str(token)
req.uri_path = path
req.payload = request.payload
req.type = defines.inv_types["CON"]
req.code = defines.inv_codes['PUT']
args = (req,)
kwargs = {}
callback = self.result_forward
err_callback = self.error
elif method == 'DELETE':
function = self.client.protocol.delete
req = Request()
req.destination = (str(host), int(port))
req.mid = self._currentMID % (1 << 16)
req.token = str(token)
req.uri_path = path
req.type = defines.inv_types["CON"]
req.code = defines.inv_codes['DELETE']
args = (req,)
kwargs = {}
callback = self.result_forward
err_callback = self.error
else:
return self.send_error(request, response, "BAD_REQUEST")
for option in request.options:
if option.safe:
kwargs[option.name] = option.value
self.send_ack([request])
operations = [(function, args, kwargs, (callback, err_callback))]
key = hash(str(host) + str(port) + str(token))
self._forward[key] = request
key = hash(str(host) + str(port) + str(self._currentMID % (1 << 16)))
self._forward_mid[key] = request
# print "************"
# print str(host), str(port), str(self._currentMID % (1 << 16))
# print req
# print "************"
key = req.mid
self.sent[key] = (req, time.time())
# self.sent[str(self._currentMID % (1 << 16))] = (req, time.time())
self.client.start(operations)
# Render_GET
# key_timer = hash(str(request.source[0]) + str(request.source[1]) + str(request.mid))
# self.timer[key_timer] = reactor.callLater(defines.SEPARATE_TIMEOUT, self.send_ack, [request])
return None