Skip to content

Commit

Permalink
Make AuthServiceProxy._batch method usable
Browse files Browse the repository at this point in the history
Split off AuthServiceProxy.get_request method to make it easier to batch RPC
requests without duplicating code and remove leading underscore from _batch
method.

This does not change any existing behavior.
  • Loading branch information
ryanofsky committed Oct 3, 2017
1 parent e02007a commit 9f67646
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions test/functional/test_framework/authproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,20 @@ def _request(self, method, path, postdata):
self.__conn.request(method, path, postdata, headers)
return self._get_response()

def __call__(self, *args, **argsn):
def get_request(self, *args, **argsn):
AuthServiceProxy.__id_count += 1

log.debug("-%s-> %s %s"%(AuthServiceProxy.__id_count, self._service_name,
json.dumps(args, default=EncodeDecimal, ensure_ascii=self.ensure_ascii)))
if args and argsn:
raise ValueError('Cannot handle both named and positional arguments')
postdata = json.dumps({'version': '1.1',
'method': self._service_name,
'params': args or argsn,
'id': AuthServiceProxy.__id_count}, default=EncodeDecimal, ensure_ascii=self.ensure_ascii)
return {'version': '1.1',
'method': self._service_name,
'params': args or argsn,
'id': AuthServiceProxy.__id_count}

def __call__(self, *args, **argsn):
postdata = json.dumps(self.get_request(*args, **argsn), default=EncodeDecimal, ensure_ascii=self.ensure_ascii)
response = self._request('POST', self.__url.path, postdata.encode('utf-8'))
if response['error'] is not None:
raise JSONRPCException(response['error'])
Expand All @@ -158,7 +161,7 @@ def __call__(self, *args, **argsn):
else:
return response['result']

def _batch(self, rpc_call_list):
def batch(self, rpc_call_list):
postdata = json.dumps(list(rpc_call_list), default=EncodeDecimal, ensure_ascii=self.ensure_ascii)
log.debug("--> "+postdata)
return self._request('POST', self.__url.path, postdata.encode('utf-8'))
Expand Down

0 comments on commit 9f67646

Please sign in to comment.