1
0

Remove dependencies: jsonrpcserver, jsonrpcclient

This commit is contained in:
ThomasV
2020-06-09 10:05:23 +02:00
parent 947af92126
commit 30f5be26ac
4 changed files with 52 additions and 29 deletions

View File

@@ -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)