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


Python option.Option类代码示例

本文整理汇总了Python中coapthon.messages.option.Option的典型用法代码示例。如果您正苦于以下问题:Python Option类的具体用法?Python Option怎么用?Python Option使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_td_coap_core_07

    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,代码行数:25,代码来源:plugtest.py

示例2: block2

    def block2(self, value):
        """
        Set the Block2 option.

        :param value: the Block2 value, (num, m, size)
        """
        option = Option()
        option.number = defines.inv_options['Block2']
        num, m, size = value

        if size > 1024:
            szx = 6
        elif 512 < size <= 1024:
            szx = 6
        elif 256 < size <= 512:
            szx = 5
        elif 128 < size <= 256:
            szx = 4
        elif 64 < size <= 128:
            szx = 3
        elif 32 < size <= 64:
            szx = 2
        elif 16 < size <= 32:
            szx = 1
        else:
            szx = 0

        value = (num << 4)
        value |= (m << 3)
        value |= szx

        option.value = value
        self.add_option(option)
开发者ID:hushuitian,项目名称:CoAPthon,代码行数:33,代码来源:response.py

示例3: add_observing

    def add_observing(self, resource, request, response):
        """
        Add an observer to a resource and sets the Observe option in the response.

        :param resource: the resource of interest
        :param request: the request
        :param response: the response
        :return: response
        """
        host, port = response.destination
        key = hash(str(host) + str(port) + str(response.token))
        observers = self._parent.relation.get(resource)
        now = int(round(time.time() * 1000))
        observe_count = resource.observe_count
        if observers is None:
            # log.msg("Initiate an observe relation between " + str(host) + ":" +
            #        str(port) + " and resource " + str(resource.path))
            observers = {key: (now, request, response)}
        elif key not in observers:
            # log.msg("Initiate an observe relation between " + str(host) + ":" +
            #         str(port) + " and resource " + str(resource.path))
            observers[key] = (now, request, response)
        else:
            # log.msg("Update observe relation between " + str(host) + ":" +
            #         str(port) + " and resource " + str(resource.path))
            old, request, response = observers[key]
            observers[key] = (now, request, response)
        self._parent.relation[resource] = observers
        option = Option()
        option.number = defines.inv_options['Observe']
        option.value = observe_count
        response.add_option(option)
        return response
开发者ID:hushuitian,项目名称:CoAPthon,代码行数:33,代码来源:observe.py

示例4: if_match

 def if_match(self, values):
     assert isinstance(values, list)
     for v in values:
         option = Option()
         option.number = defines.OptionRegistry.IF_MATCH.number
         option.value = v
         self.add_option(option)
开发者ID:yukusu,项目名称:IoT-Rasp,代码行数:7,代码来源:request.py

示例5: delete

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

示例6: test_get_not_found

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

示例7: test_long

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

示例8: add_block2

    def add_block2(self, num, m, size):
        """
        Add and format a Block2 option to a request.

        :param num: num
        :param m: more blocks
        :param size: size in byte
        """
        option = Option()
        option.number = defines.inv_options['Block2']
        if size > 1024:
            szx = 6
        elif 512 < size <= 1024:
            szx = 6
        elif 256 < size <= 512:
            szx = 5
        elif 128 < size <= 256:
            szx = 4
        elif 64 < size <= 128:
            szx = 3
        elif 32 < size <= 64:
            szx = 2
        elif 16 < size <= 32:
            szx = 1
        else:
            szx = 0
        value = (num << 4)
        value |= (m << 3)
        value |= szx

        option.value = value
        self.add_option(option)
开发者ID:hushuitian,项目名称:CoAPthon,代码行数:32,代码来源:request.py

示例9: test_get_separate

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

示例10: block2

    def block2(self, value):
        option = Option()
        option.number = defines.OptionRegistry.BLOCK2.number
        num, m, size = value
        if size > 1024:
            szx = 6
        elif 512 < size <= 1024:
            szx = 6
        elif 256 < size <= 512:
            szx = 5
        elif 128 < size <= 256:
            szx = 4
        elif 64 < size <= 128:
            szx = 3
        elif 32 < size <= 64:
            szx = 2
        elif 16 < size <= 32:
            szx = 1
        else:
            szx = 0

        value = (num << 4)
        value |= (m << 3)
        value |= szx

        option.value = value
        self.add_option(option)
开发者ID:yukusu,项目名称:IoT-Rasp,代码行数:27,代码来源:message.py

示例11: location_query

 def location_query(self, value):
     del self.location_query
     queries = value.split("&")
     for q in queries:
         option = Option()
         option.number = defines.OptionRegistry.LOCATION_QUERY.number
         option.value = str(q)
         self.add_option(option)
开发者ID:yukusu,项目名称:IoT-Rasp,代码行数:8,代码来源:response.py

示例12: add_if_none_match

 def add_if_none_match(self):
     """
     Add the if-none-match option to the request.
     """
     option = Option()
     option.number = defines.OptionRegistry.IF_NONE_MATCH.number
     option.value = None
     self.add_option(option)
开发者ID:Tanganelli,项目名称:CoAPthon,代码行数:8,代码来源:request.py

示例13: block1

    def block1(self, value):
        option = Option()
        option.number = defines.inv_options["Block1"]
        num, m, size = value
        value = num << 4
        value |= m << 3
        value |= size

        option.value = value
开发者ID:DavideFoti,项目名称:CoAPthon,代码行数:9,代码来源:response.py

示例14: proxy_uri

    def proxy_uri(self, uri):
        """
        Set the Proxy-Uri option of a request.

        :param uri: the Proxy-Uri values
        """
        option = Option()
        option.number = defines.inv_options['Proxy-Uri']
        option.value = str(uri)
        self.add_option(option)
开发者ID:DavideFoti,项目名称:CoAPthon,代码行数:10,代码来源:request.py

示例15: etag

    def etag(self, etag):
        """
        Add an ETag option to the message.

        :param etag: the etag
        """
        option = Option()
        option.number = defines.OptionRegistry.ETAG.number
        option.value = etag
        self.add_option(option)
开发者ID:yukusu,项目名称:IoT-Rasp,代码行数:10,代码来源:message.py


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