Skip to content

Commit 9f67646

Browse files
committed
Make AuthServiceProxy._batch method usable
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.
1 parent e02007a commit 9f67646

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

test/functional/test_framework/authproxy.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,20 @@ def _request(self, method, path, postdata):
138138
self.__conn.request(method, path, postdata, headers)
139139
return self._get_response()
140140

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

144144
log.debug("-%s-> %s %s"%(AuthServiceProxy.__id_count, self._service_name,
145145
json.dumps(args, default=EncodeDecimal, ensure_ascii=self.ensure_ascii)))
146146
if args and argsn:
147147
raise ValueError('Cannot handle both named and positional arguments')
148-
postdata = json.dumps({'version': '1.1',
149-
'method': self._service_name,
150-
'params': args or argsn,
151-
'id': AuthServiceProxy.__id_count}, default=EncodeDecimal, ensure_ascii=self.ensure_ascii)
148+
return {'version': '1.1',
149+
'method': self._service_name,
150+
'params': args or argsn,
151+
'id': AuthServiceProxy.__id_count}
152+
153+
def __call__(self, *args, **argsn):
154+
postdata = json.dumps(self.get_request(*args, **argsn), default=EncodeDecimal, ensure_ascii=self.ensure_ascii)
152155
response = self._request('POST', self.__url.path, postdata.encode('utf-8'))
153156
if response['error'] is not None:
154157
raise JSONRPCException(response['error'])
@@ -158,7 +161,7 @@ def __call__(self, *args, **argsn):
158161
else:
159162
return response['result']
160163

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

0 commit comments

Comments
 (0)