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


Python Request.mid方法代码示例

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


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

示例1: delete

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

示例2: discover

# 需要导入模块: from coapthon.messages.request import Request [as 别名]
# 或者: from coapthon.messages.request.Request import mid [as 别名]
 def discover(self, client_callback, *args, **kwargs):
     req = Request()
     if "Token" in kwargs.keys():
         req.token = kwargs.get("Token")
     if "MID" in kwargs.keys():
         req.mid = kwargs.get("MID")
     if "Server" in kwargs.keys():
         req.destination = kwargs.get("Server")
         del kwargs["Server"]
     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)
开发者ID:hushuitian,项目名称:CoAPthon,代码行数:15,代码来源:coap_protocol.py

示例3: forward_request

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


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