本文整理汇总了Python中request.Request.from_dict方法的典型用法代码示例。如果您正苦于以下问题:Python Request.from_dict方法的具体用法?Python Request.from_dict怎么用?Python Request.from_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类request.Request
的用法示例。
在下文中一共展示了Request.from_dict方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dispatch_rpcdata
# 需要导入模块: from request import Request [as 别名]
# 或者: from request.Request import from_dict [as 别名]
def dispatch_rpcdata(self, rpc_worker, rpcdata):
try:
json_data, peer_id = rpcdata
obj = json.loads(json_data, object_hook=extended_decoder_hook)
except Exception as e:
log.error("Can't parse JSON for peer:", peer_id, json_data)
log.debug_traceback()
return True
req = Request.from_dict(obj)
# is someone waiting on this response?
rpc_worker.data = "Request %s started" % req.request_id
if req.is_response() and req.request_id in self.pending:
rpc_worker.data = "Request %s processing response" % req.request_id
oldreq = self.pending.get(req.request_id)
del self.pending[req.request_id]
oldreq.result = req.result
oldreq.state = req.state
oldreq.diagnostic = req.diagnostic
with self.lock:
self.condition.notify()
elif req.is_request():
rpc_worker.data = "Request %s calling local %s (%s)" % (req.request_id, req.method, req.params)
# actually call the local handler
self.handle_request(req, peer_id)
# and send back the response
rpc_worker.data = "Request %s sending response" % req.request_id
if req.request_id is not None:
self.put(req, peer_id)
rpc_worker.data = "Request %s done (%s)" % (req.request_id, req.method)
return True
示例2: dispatch_rpcdata
# 需要导入模块: from request import Request [as 别名]
# 或者: from request.Request import from_dict [as 别名]
def dispatch_rpcdata(self, rpc_worker, rpcdata):
json_data, peer_id = rpcdata
#print ' [%s --> %s] %s' % (peer_id, self.node_id, json_data)
#py_data = json.loads("[" + json_data.replace("}{", "}, {") + "]")
obj = json.loads(json_data)
req = Request.from_dict(obj)
# is someone waiting on this response?
if req.is_response() and req.request_id in self.pending:
oldreq = self.pending.get(req.request_id)
oldreq.result = req.result
oldreq.state = req.state
oldreq.diagnostic = req.diagnostic
with self.lock:
self.condition.notify()
elif req.is_request():
# actually call the local handler
self.handle_request(req, peer_id)
# and send back the response
if req.request_id is not None:
self.put(req, peer_id)
return True