当前位置: 首页>>代码示例>>Python>>正文


Python Request.payload方法代码示例

本文整理汇总了Python中coapthon.messages.request.Request.payload方法的典型用法代码示例。如果您正苦于以下问题:Python Request.payload方法的具体用法?Python Request.payload怎么用?Python Request.payload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在coapthon.messages.request.Request的用法示例。


在下文中一共展示了Request.payload方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_lookup_expired_ep

# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import payload [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&lt=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)
开发者ID:Tanganelli,项目名称:CoAPthon,代码行数:33,代码来源:resourcedirectory_test.py

示例2: test_wrong_ep

# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import payload [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&lt=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)])
开发者ID:Tanganelli,项目名称:CoAPthon,代码行数:33,代码来源:resourcedirectory_test.py

示例3: map

# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import payload [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
开发者ID:DavideFoti,项目名称:CoAPthon,代码行数:35,代码来源:reverse_coap_proxy.py

示例4: test_delete

# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import payload [as 别名]
    def test_delete(self):
        print("Delete")
        client = HelperClient(self.server_address)
        path = "rd?ep=endpoint1&lt=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)])
开发者ID:Tanganelli,项目名称:CoAPthon,代码行数:33,代码来源:resourcedirectory_test.py

示例5: test_td_coap_core_07

# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import payload [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)
开发者ID:Cereal84,项目名称:CoAPthon,代码行数:27,代码来源:plugtest.py

示例6: test_post_and_get_storage

# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import payload [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)
开发者ID:hushuitian,项目名称:CoAPthon,代码行数:59,代码来源:test_coapserver.py

示例7: put

# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import payload [as 别名]
 def put(self, path, payload, callback=None):  # pragma: no cover
     request = Request()
     request.destination = self.server
     request.code = defines.Codes.PUT.number
     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
开发者ID:Erguotou,项目名称:CoAPthon,代码行数:15,代码来源:helperclient.py

示例8: _create_test_sequence

# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import payload [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
开发者ID:Tanganelli,项目名称:CoAPthon,代码行数:50,代码来源:test_secure.py

示例9: put

# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import payload [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)
开发者ID:johanzander,项目名称:CoAPthon,代码行数:18,代码来源:coap_protocol.py

示例10: _handle_request

# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import payload [as 别名]
    def _handle_request(self, transaction, new_resource):
        """
        Forward requests. Used by reverse proxies to also create new virtual resources on the proxy 
        in case of created resources
        
        :type new_resource: bool
        :type transaction: Transaction
        :param transaction: the transaction that owns the request
        :rtype : Transaction
        :param new_resource: if the request will generate a new resource 
        :return: the edited transaction
        """
        client = HelperClient(transaction.resource.remote_server)
        request = Request()
        request.options = copy.deepcopy(transaction.request.options)
        del request.block2
        del request.block1
        del request.uri_path
        del request.proxy_uri
        del request.proxy_schema
        # TODO handle observing
        del request.observe
        # request.observe = transaction.request.observe

        request.uri_path = "/".join(transaction.request.uri_path.split("/")[1:])
        request.destination = transaction.resource.remote_server
        request.payload = transaction.request.payload
        request.code = transaction.request.code
        response = client.send_request(request)
        client.stop()
        transaction.response.payload = response.payload
        transaction.response.code = response.code
        transaction.response.options = response.options
        if response.code == defines.Codes.CREATED.number:
            lp = transaction.response.location_path
            del transaction.response.location_path
            transaction.response.location_path = transaction.request.uri_path.split("/")[0] + "/" + lp
            # TODO handle observing
            if new_resource:
                resource = RemoteResource('server', transaction.resource.remote_server, lp, coap_server=self,
                                          visible=True,
                                          observable=False,
                                          allow_children=True)
                self._server.add_resource(transaction.response.location_path, resource)
        if response.code == defines.Codes.DELETED.number:
            del self._server.root["/" + transaction.request.uri_path]
        return transaction
开发者ID:Tanganelli,项目名称:CoAPthon,代码行数:49,代码来源:forwardLayer.py

示例11: test_delete_res_not_found

# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import payload [as 别名]
    def test_delete_res_not_found(self):
        print("Resource not found on delete")
        path = "rd/4521"
        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.NOT_FOUND.number
        expected.token = None
        expected.content_type = 0
        expected.payload = None

        self.current_mid += 1
        self._test_check([(req, expected)])
开发者ID:Tanganelli,项目名称:CoAPthon,代码行数:24,代码来源:resourcedirectory_test.py

示例12: put

# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import payload [as 别名]
    def put(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
            ip, port = endpoint
            payload = request.payload
        else:
            request = Request()
            path = kwargs["path"]
            payload = kwargs["payload"]
            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["PUT"]
        request.payload = payload
        self.send(request, endpoint)
        self.condition.acquire()
        self.condition.wait()
        message = self._response
        key = hash(str(ip) + str(port) + str(message.mid))
        if (
            message.type == defines.inv_types["ACK"]
            and message.code == defines.inv_codes["EMPTY"]
            and key in self.sent.keys()
        ):
            # Separate Response
            self.send(request, endpoint)
            self.condition.acquire()
            self.condition.wait()
            message = self._response
        return message
开发者ID:DavideFoti,项目名称:CoAPthon,代码行数:41,代码来源:coap_synchronous.py

示例13: test_edit_resource

# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import payload [as 别名]
    def test_edit_resource(self):
        print "TEST_EDIT_RESOURCE"
        path = "/obs"
        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.payload = "<value>test</value>"

        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 = "/obs"

        self.current_mid += 1
        self._test_with_client([(req, expected)])
开发者ID:yukusu,项目名称:IoT-Rasp,代码行数:24,代码来源:plugtest.py

示例14: test_td_coap_core_07

# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import payload [as 别名]
    def test_td_coap_core_07(self):
        print "TD_COAP_CORE_07"
        path = "/test"
        req = Request()

        req.code = defines.Codes.PUT.number
        req.uri_path = path
        req.type = defines.Types["NON"]
        req.content_type = defines.Content_types["application/xml"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.payload = "<value>test</value>"

        expected = Response()
        expected.type = defines.Types["NON"]
        expected._mid = None
        expected.code = defines.Codes.CHANGED.number
        expected.token = None
        expected.payload = None

        self.current_mid += 1
        self._test_with_client([(req, expected)])
开发者ID:yukusu,项目名称:IoT-Rasp,代码行数:24,代码来源:plugtest.py

示例15: test_uri_discovery

# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import payload [as 别名]
    def test_uri_discovery(self):
        print("Uri discovery")
        path = ".well-known/core"
        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 = '</rd-lookup/res>;rt="core.rd-lookup-res";ct=40,</rd>;rt="core.rd";ct=40,' \
                           '</rd-lookup/ep>;rt="core.rd-lookup-ep";ct=40'

        self.current_mid += 1
        self._test_check([(req, expected)])
开发者ID:Tanganelli,项目名称:CoAPthon,代码行数:25,代码来源:resourcedirectory_test.py


注:本文中的coapthon.messages.request.Request.payload方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。