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


Python DotDict.clwbody方法代码示例

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


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

示例1: periodic_send

# 需要导入模块: from utils.dotdict import DotDict [as 别名]
# 或者: from utils.dotdict.DotDict import clwbody [as 别名]
    def periodic_send(self):
        """Send out request and receive the response.

        This should be guarded by the mutex, since the sock
        maybe shared by many clients.
        """
        while True: 
            # if there are some requests to be send, get one item from queue and
            # send it
            if self.send_queue.qsize() != 0:
                request = self.send_queue.get(True, 1)
                try:
                    self.send_request(request['packet'])

                    gf = GFCheck(request['packet']) 
                    gfhead = gf.heads[0]
                    # add the callback to wait response dict, and the key is seq number 
                    if request['callback']:
                        if gfhead.command == '0010':
                            sp = SendParser(gf.datas[0])
                            clw = S_CLWCheck(sp.gfbody.Content)
                            r_key = ("%s%s" % (sp.gfbody.Terminal_id, clw.head.command)).replace(' ','')
                            r_value = {'callback':request['callback'],
                                       'timestamp':time()}
                            if self.wait_response_queue.has_key(r_key):
                                self.wait_response_queue[r_key].append(r_value)
                            else:
                                self.wait_response_queue[r_key] = [r_value,]

                except socket.error as e:
                    logging.exception("sock error: %s", e.args)
                    # we need clear the wait response queue, avoid dead lock.
                    self._clear_wait_response_queue()
                    self.is_alive = False
                    self.reconnect()
                except Exception as e:
                    #TODO: can never see this
                    logging.exception("send error: %s", e.args)
                    response = ""

            # check whether there is some response to receive.  
            # if true, recv response as much as possible.(recv response is high priority)
            try:
                while(True):
                    infds, _, _ = select.select([self.__sock], [], [], 0.1)
                    if len(infds) > 0:
                        response = self.recv_response()
                        logging.info('[GFPROXY] Recv whole packet: %s', response)

                        gf = GFCheck(response)
                        gfheads = gf.heads
                        gfdatas = gf.datas

                        for gfhead, gfdata in zip(gfheads, gfdatas):
                            success, info = GFMessageHelper.format_gf_message(gfhead.status)
                            resp = DotDict(success=success,
                                           info=info,
                                           clwhead={},
                                           clwbody='')
                            if gfhead.command == '0020': # active_test, just give a response
                                logging.info("active_test_resp:\n%s", gfhead)
                                args = DotDict(seq=gfhead.seq)
                                atc = ActiveTestRespComposer(args)
                                self.send_request(atc.buf)
                            elif gfhead.command == '1010':
                                # NOTE: should check the response whether okay or nt
                                # if not 0000, callback
                                logging.info("send_data_resp\n%s, gfdata: %r", gfhead, gfdata)
                                srp = SendRespParser(gfdata)
                                is_reboot = (srp.gfbody.command.strip() == S_MESSAGE_TYPE.REBOOT)
                                if (is_reboot or (gfhead.status != '0000')):
                                    r_key = ("%s%s" % (srp.gfbody.Terminal_id, srp.gfbody.command)).replace(' ','')
                                    if self.wait_response_queue.has_key(r_key):
                                        callback = self.wait_response_queue[r_key][0]['callback']
                                        callback(resp)
                                        del self.wait_response_queue[r_key][0]
                                        if len(self.wait_response_queue[r_key]) == 0:
                                            del self.wait_response_queue[r_key]
                            elif gfhead.command == '0011': # upload_data
                                logging.info("upload_data\n%s, gfdata: %r", gfhead, gfdata)
                                args = DotDict(seq=gfhead.seq)
                                udrc = UploadDataRespComposer(args)
                                logging.info("upload_data_resp\n%r", udrc.buf)
                                self.send_request(udrc.buf)
                                # we got a response, and call the correspond callback, 
                                # and delete from wait response queue
                                udp = UploadDataParser(gfdata)
                                tc = T_CLWCheck(udp.content)
                                clwhead = tc.head
                                clwbody = tc.body

                                r_key = ("%s%s" % (clwhead.dev_id, 'S'+clwhead.command[1:])).replace(' ','')
                                if self.wait_response_queue.has_key(r_key):
                                    logging.info("[GFPROXY] UWEB-->GF-->UWEB. r_key: %s",
                                                 r_key)
                                    callback = self.wait_response_queue[r_key][0]['callback']
                                    resp.clwbody= clwbody
                                    resp.clwhead = clwhead
                                    callback(resp)
                                    del self.wait_response_queue[r_key][0]
#.........这里部分代码省略.........
开发者ID:jcsy521,项目名称:ydws,代码行数:103,代码来源:base.py


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