Remove dependencies: jsonrpcserver, jsonrpcclient
This commit is contained in:
@@ -1368,3 +1368,30 @@ class MySocksProxy(aiorpcx.SOCKSProxy):
|
||||
else:
|
||||
raise NotImplementedError # http proxy not available with aiorpcx
|
||||
return ret
|
||||
|
||||
|
||||
class myAiohttpClient:
|
||||
|
||||
def __init__(self, session, url):
|
||||
self.session = session
|
||||
self.url = url
|
||||
|
||||
async def request(self, endpoint, *args):
|
||||
data = '{"jsonrpc": "2.0", "id":"0", "method":"%s", "params": %s }' %(endpoint, json.dumps(args))
|
||||
async with self.session.post(self.url, data=data) as resp:
|
||||
if resp.status == 200:
|
||||
r = await resp.json()
|
||||
result = r.get('result')
|
||||
error = r.get('error')
|
||||
if error:
|
||||
return 'Error: ' + str(error)
|
||||
else:
|
||||
return result
|
||||
else:
|
||||
text = await resp.text()
|
||||
return 'Error: ' + str(text)
|
||||
|
||||
def add_method(self, endpoint):
|
||||
async def coro(*args):
|
||||
return await self.request(endpoint, *args)
|
||||
setattr(self, endpoint, coro)
|
||||
|
||||
Reference in New Issue
Block a user