json_rpc.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:xr-telemetry-m2m-web 作者: cisco 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号