本文整理汇总了Python中coapthon.messages.request.Request._mid方法的典型用法代码示例。如果您正苦于以下问题:Python Request._mid方法的具体用法?Python Request._mid怎么用?Python Request._mid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类coapthon.messages.request.Request
的用法示例。
在下文中一共展示了Request._mid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_post_and_get_storage
# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import _mid [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)
示例2: _create_test_sequence
# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import _mid [as 别名]
def _create_test_sequence(self, bValidResponse=True):
exchange = list()
req = Request()
req.code = defines.Codes.POST.number
req.uri_path = "/storage/new_res?id=1"
req.type = defines.Types["CON"]
req._mid = self.current_mid
req.destination = self.server_address
req.payload = "test"
req.add_if_none_match()
if bValidResponse:
expected = Response()
expected.type = defines.Types["ACK"]
expected._mid = self.current_mid
expected.code = defines.Codes.CREATED.number
expected.token = None
expected.payload = None
expected.location_path = "storage/new_res"
expected.location_query = "id=1"
else:
expected = None
exchange.append((req, expected))
self.current_mid += 1
req = Request()
req.code = defines.Codes.GET.number
req.uri_path = "/storage/new_res"
req.type = defines.Types["CON"]
req._mid = self.current_mid
req.destination = self.server_address
req.if_match = ["test", "not"]
if bValidResponse:
expected = Response()
expected.type = defines.Types["ACK"]
expected._mid = self.current_mid
expected.code = defines.Codes.CONTENT.number
expected.token = None
expected.payload = "test"
else:
expected = None
exchange.append((req, expected))
self.current_mid += 1
return exchange
示例3: test_lookup_expired_ep
# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import _mid [as 别名]
def test_lookup_expired_ep(self):
print("Expired endpoint lookup")
client = HelperClient(self.server_address)
path = "rd?ep=node1&con=coap://local-proxy-old.example.com:5683<=60"
ct = {'content_type': defines.Content_types["application/link-format"]}
payload = '</sensors/temp>;ct=41;rt="temperature-c";if="sensor";anchor="coap://spurious.example.com:5683",' \
'</sensors/light>;ct=41;rt="light-lux";if="sensor"'
client.post(path, payload, None, None, **ct)
client.stop()
path = "rd-lookup/ep?ep=node1&rt=temperature-c"
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.content_type = 0
req.payload = None
expected = Response()
expected.type = defines.Types["ACK"]
expected._mid = self.current_mid
expected.code = defines.Codes.CONTENT.number
expected.token = None
expected.content_type = defines.Content_types["application/link-format"]
expected.payload = None
self.current_mid += 1
# After 61 seconds the resource will be expired
self._test_check([(req, expected)], 61)
示例4: test_wrong_ep
# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import _mid [as 别名]
def test_wrong_ep(self):
print("Endpoint name already exists")
client = HelperClient(self.server_address)
path = "rd?ep=node1&con=coap://local-proxy-old.example.com:5683<=60"
ct = {'content_type': defines.Content_types["application/link-format"]}
payload = '</sensors/temp>;ct=41;rt="temperature-c";if="sensor";anchor="coap://spurious.example.com:5683",' \
'</sensors/light>;ct=41;rt="light-lux";if="sensor"'
client.post(path, payload, None, None, **ct)
client.stop()
path = "rd?ep=node1&con=coap://local-proxy-old.example.com:5683"
req = Request()
req.code = defines.Codes.POST.number
req.uri_path = path
req.type = defines.Types["CON"]
req._mid = self.current_mid
req.destination = self.server_address
req.content_type = defines.Content_types["application/link-format"]
req.payload = '</sensors/temp>;ct=41;rt="temperature-c";if="sensor";' \
'anchor="coap://spurious.example.com:5683",</sensors/light>;ct=41;rt="light-lux";if="sensor"'
expected = Response()
expected.type = defines.Types["ACK"]
expected._mid = self.current_mid
expected.code = defines.Codes.SERVICE_UNAVAILABLE.number
expected.token = None
expected.content_type = 0
expected.payload = None
self.current_mid += 1
self._test_check([(req, expected)])
示例5: test_delete
# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import _mid [as 别名]
def test_delete(self):
print("Delete")
client = HelperClient(self.server_address)
path = "rd?ep=endpoint1<=500&con=coap://local-proxy-old.example.com:5683&et=oic.d.sensor"
ct = {'content_type': defines.Content_types["application/link-format"]}
payload = '</sensors/temp>;ct=41;rt="temperature-c";if="sensor";anchor="coap://spurious.example.com:5683",' \
'</sensors/light>;ct=41;rt="light-lux";if="sensor"'
response = client.post(path, payload, None, None, **ct)
loc_path = response.location_path
client.stop()
path = loc_path
req = Request()
req.code = defines.Codes.DELETE.number
req.uri_path = path
req.type = defines.Types["CON"]
req._mid = self.current_mid
req.destination = self.server_address
req.content_type = 0
req.payload = None
expected = Response()
expected.type = defines.Types["ACK"]
expected._mid = self.current_mid
expected.code = defines.Codes.DELETED.number
expected.token = None
expected.content_type = 0
expected.payload = None
self.current_mid += 1
self._test_check([(req, expected)])
示例6: test_td_coap_core_07
# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import _mid [as 别名]
def test_td_coap_core_07(self):
print "TD_COAP_CORE_07"
path = "/test"
req = Request()
req.code = defines.inv_codes['PUT']
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["CHANGED"]
expected.token = None
expected.payload = None
self.current_mid += 1
self._test_plugtest(req, expected)
示例7: map
# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import _mid [as 别名]
def map(self, request):
path = request.uri_path
if request.uri_path == defines.DISCOVERY_URL:
response = Response()
response.destination = request.source
response = self._resource_layer.discover(request, response)
self.result_forward(response, request)
server = self.root.find_complete(path)
if server is not None:
new_request = Request()
segments = server.find_path().split("/")
path = segments[2:]
path = "/".join(path)
segments = segments[1].split(":")
host = segments[0]
port = int(segments[1])
# new_request.destination = (host, port)
new_request.source = request.source
new_request.type = request.type
new_request._mid = (self._currentMID + 1) % (1 << 16)
new_request.code = request.code
new_request.proxy_uri = "coap://" + str(host) + ":" + str(port) + "/" + path
new_request.payload = request.payload
for option in request.options:
if option.name == defines.inv_options["Uri-Path"]:
continue
if option.name == defines.inv_options["Uri-Query"]:
continue
if option.name == defines.inv_options["Uri-Host"]:
continue
new_request.add_option(option)
return new_request
return None
示例8: test_get_separate
# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import _mid [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)
示例9: test_get_not_found
# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import _mid [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)
示例10: test_td_coap_obs_01
# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import _mid [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)])
示例11: discover_remote
# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import _mid [as 别名]
def discover_remote(self, destination):
request = Request()
assert (isinstance(destination, str))
split = destination.split(":", 1)
host = split[0]
port = int(split[1])
server = (host, port)
request.destination = (host, port)
request.type = defines.inv_types["CON"]
request._mid = (self._currentMID + 1) % (1 << 16)
request.code = defines.inv_codes["GET"]
uri = "/" + defines.DISCOVERY_URL
request.proxy_uri = uri
client = HelperClient(server, True)
token = self.generate_token()
function = client.protocol.get
args = (uri,)
kwargs = {"Token": str(token)}
callback = self.discover_remote_results
err_callback = self.discover_remote_error
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((client.starting_mid + 1) % (1 << 16)))
self._forward_mid[key] = request
client.start(operations)
示例12: test_long
# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import _mid [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)])
示例13: test_retrasnmissions
# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import _mid [as 别名]
def test_retrasnmissions(self):
print "Retransmissions"
path = "/separate"
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
expected = Response()
expected.type = defines.Types["ACK"]
expected._mid = self.current_mid
expected.code = None
expected.token = None
expected.payload = None
expected2 = Response()
expected2.type = defines.Types["CON"]
expected2._mid = self.server_mid
expected2.code = defines.Codes.CONTENT.number
expected2.token = None
expected2.payload = "Separate Resource"
self.current_mid += 1
self._test_plugtest([(req, expected), (None, expected2), (None, expected2), (None, expected2)])
示例14: test_td_coap_core_09
# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import _mid [as 别名]
def test_td_coap_core_09(self):
print "TD_COAP_CORE_09"
path = "/separate"
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
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._mid = None
expected2.code = defines.responses["CONTENT"]
expected2.token = None
expected2.payload = "Separate Resource"
self.current_mid += 1
self._test_plugtest_separate(req, expected, expected2)
示例15: test_td_coap_block_01
# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import _mid [as 别名]
def test_td_coap_block_01(self):
print "TD_COAP_BLOCK_01"
path = "/large"
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.add_block2(0, 0, 1024)
expected = Response()
expected.type = defines.inv_types["ACK"]
expected._mid = self.current_mid
expected.code = defines.responses["CONTENT"]
expected.token = None
expected.payload = None
expected.block2 = (0, 1, 1024)
exchange1 = (req, expected)
self.current_mid += 1
self.server_mid += 1
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.add_block2(1, 0, 1024)
expected = Response()
expected.type = defines.inv_types["ACK"]
expected._mid = self.current_mid
expected.code = defines.responses["CONTENT"]
expected.token = None
expected.payload = None
expected.block2 = (1, 0, 1024)
exchange2 = (req, expected)
self.current_mid += 1
self.server_mid += 1
self._test_plugtest([exchange1, exchange2])