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


Python Request.observe方法代码示例

本文整理汇总了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)])
开发者ID:hushuitian,项目名称:CoAPthon,代码行数:33,代码来源:plugtest.py

示例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)
开发者ID:hushuitian,项目名称:CoAPthon,代码行数:34,代码来源:coap_protocol.py

示例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
开发者ID:Erguotou,项目名称:CoAPthon,代码行数:16,代码来源:helperclient.py

示例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)
开发者ID:johanzander,项目名称:CoAPthon,代码行数:19,代码来源:coap_protocol.py

示例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)])
开发者ID:yukusu,项目名称:IoT-Rasp,代码行数:43,代码来源:plugtest.py

示例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)
开发者ID:DavideFoti,项目名称:CoAPthon,代码行数:23,代码来源:coap_synchronous.py


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