def _reply(self, json_reply):
"""
Handle a reply that came in over the transport provided
"""
if not json_reply.startswith('{'):
self.sdata.log('Received non-JSON data: "{}"'.format(json_reply))
return
reply = json.loads(json_reply, object_pairs_hook=OrderedDict)
if reply['jsonrpc'] != '2.0' or 'id' not in reply or reply['id'] is None:
self.sdata.log('Received bad JSON-RPC reply: {}'.format(json_reply))
if len(self.pending_reply_map) == 1:
# lucky! can guess a pending reply to kill
this_id = self.pending_reply_map.keys()[0]
d = self.pending_reply_map[this_id]
del self.pending_reply_map[this_id]
e = JsonRpcException('Bad reply: {}'.format(json_reply))
d.errback(e)
return
this_id = int(reply['id'])
if 'method' in reply and this_id in self.pending_reply_map:
self.sdata.log('Got echo of request for {}, ignoring'.format(this_id))
else:
d = self.pending_reply_map[this_id]
del self.pending_reply_map[this_id]
d.callback(reply)
评论列表
文章目录