本文整理汇总了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]
#.........这里部分代码省略.........