mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 10:43:19 -03:00
Merge bitcoin/bitcoin#28011: test: Rename EncodeDecimal to serialization_fallback
fabd34873c
test: Rename EncodeDecimal to serialization_fallback (MarcoFalke) Pull request description: The new name better explains that the function handles fallbacks, without listing all in the function name. ACKs for top commit: theStack: ACKfabd34873c
Tree-SHA512: a0405aab2bfb2fd10c61b51b4eb767053b25b0d914d2dac006dd3eaf360fbc6f3a444bc7b580ab8469ec492fe4358cfad5943adde4a7c8f783032ceef5cc5383
This commit is contained in:
commit
76240ce55d
2 changed files with 7 additions and 7 deletions
|
@ -60,7 +60,7 @@ class JSONRPCException(Exception):
|
|||
self.http_status = http_status
|
||||
|
||||
|
||||
def EncodeDecimal(o):
|
||||
def serialization_fallback(o):
|
||||
if isinstance(o, decimal.Decimal):
|
||||
return str(o)
|
||||
if isinstance(o, pathlib.Path):
|
||||
|
@ -111,7 +111,7 @@ class AuthServiceProxy():
|
|||
log.debug("-{}-> {} {}".format(
|
||||
AuthServiceProxy.__id_count,
|
||||
self._service_name,
|
||||
json.dumps(args or argsn, default=EncodeDecimal, ensure_ascii=self.ensure_ascii),
|
||||
json.dumps(args or argsn, default=serialization_fallback, ensure_ascii=self.ensure_ascii),
|
||||
))
|
||||
if args and argsn:
|
||||
params = dict(args=args, **argsn)
|
||||
|
@ -123,7 +123,7 @@ class AuthServiceProxy():
|
|||
'id': AuthServiceProxy.__id_count}
|
||||
|
||||
def __call__(self, *args, **argsn):
|
||||
postdata = json.dumps(self.get_request(*args, **argsn), default=EncodeDecimal, ensure_ascii=self.ensure_ascii)
|
||||
postdata = json.dumps(self.get_request(*args, **argsn), default=serialization_fallback, ensure_ascii=self.ensure_ascii)
|
||||
response, status = self._request('POST', self.__url.path, postdata.encode('utf-8'))
|
||||
if response['error'] is not None:
|
||||
raise JSONRPCException(response['error'], status)
|
||||
|
@ -137,7 +137,7 @@ class AuthServiceProxy():
|
|||
return response['result']
|
||||
|
||||
def batch(self, rpc_call_list):
|
||||
postdata = json.dumps(list(rpc_call_list), default=EncodeDecimal, ensure_ascii=self.ensure_ascii)
|
||||
postdata = json.dumps(list(rpc_call_list), default=serialization_fallback, ensure_ascii=self.ensure_ascii)
|
||||
log.debug("--> " + postdata)
|
||||
response, status = self._request('POST', self.__url.path, postdata.encode('utf-8'))
|
||||
if status != HTTPStatus.OK:
|
||||
|
@ -170,7 +170,7 @@ class AuthServiceProxy():
|
|||
response = json.loads(responsedata, parse_float=decimal.Decimal)
|
||||
elapsed = time.time() - req_start_time
|
||||
if "error" in response and response["error"] is None:
|
||||
log.debug("<-%s- [%.6f] %s" % (response["id"], elapsed, json.dumps(response["result"], default=EncodeDecimal, ensure_ascii=self.ensure_ascii)))
|
||||
log.debug("<-%s- [%.6f] %s" % (response["id"], elapsed, json.dumps(response["result"], default=serialization_fallback, ensure_ascii=self.ensure_ascii)))
|
||||
else:
|
||||
log.debug("<-- [%.6f] %s" % (elapsed, responsedata))
|
||||
return response, http_response.status
|
||||
|
|
|
@ -24,7 +24,7 @@ from pathlib import Path
|
|||
|
||||
from .authproxy import (
|
||||
JSONRPCException,
|
||||
EncodeDecimal,
|
||||
serialization_fallback,
|
||||
)
|
||||
from .descriptors import descsum_create
|
||||
from .p2p import P2P_SUBVERSION
|
||||
|
@ -714,7 +714,7 @@ def arg_to_cli(arg):
|
|||
elif arg is None:
|
||||
return 'null'
|
||||
elif isinstance(arg, dict) or isinstance(arg, list):
|
||||
return json.dumps(arg, default=EncodeDecimal)
|
||||
return json.dumps(arg, default=serialization_fallback)
|
||||
else:
|
||||
return str(arg)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue