2018-04-30 13:37:23 +02:00
|
|
|
import json
|
|
|
|
import socket
|
2018-04-25 21:44:36 +02:00
|
|
|
|
2019-08-03 13:46:39 +02:00
|
|
|
class Client:
|
2018-05-02 12:42:13 +02:00
|
|
|
def __init__(self, addr):
|
|
|
|
self.s = socket.create_connection(addr)
|
|
|
|
self.f = self.s.makefile('r')
|
|
|
|
self.id = 0
|
|
|
|
|
2021-06-13 13:57:55 +02:00
|
|
|
def call(self, requests):
|
|
|
|
requests = list(requests)
|
|
|
|
for request in requests:
|
|
|
|
request['id'] = self.id
|
|
|
|
request['jsonrpc'] = '2.0'
|
|
|
|
self.id += 1
|
2021-05-21 12:56:04 +02:00
|
|
|
|
|
|
|
msg = json.dumps(requests) + '\n'
|
2018-05-02 12:42:13 +02:00
|
|
|
self.s.sendall(msg.encode('ascii'))
|
2021-06-13 13:57:55 +02:00
|
|
|
response = json.loads(self.f.readline())
|
|
|
|
return [r['result'] for r in response]
|
|
|
|
|
|
|
|
|
|
|
|
def request(method, *args):
|
|
|
|
return {'method': method, 'params': list(args)}
|