test: Rename EncodeDecimal to serialization_fallback

The new name better explains that the function handles fallbacks,
without listing all in the function name.
This commit is contained in:
MarcoFalke 2023-06-29 13:42:59 +02:00
parent c6287faae4
commit fabd34873c
No known key found for this signature in database
2 changed files with 7 additions and 7 deletions

View File

@ -60,7 +60,7 @@ class JSONRPCException(Exception):
self.http_status = http_status self.http_status = http_status
def EncodeDecimal(o): def serialization_fallback(o):
if isinstance(o, decimal.Decimal): if isinstance(o, decimal.Decimal):
return str(o) return str(o)
if isinstance(o, pathlib.Path): if isinstance(o, pathlib.Path):
@ -111,7 +111,7 @@ class AuthServiceProxy():
log.debug("-{}-> {} {}".format( log.debug("-{}-> {} {}".format(
AuthServiceProxy.__id_count, AuthServiceProxy.__id_count,
self._service_name, 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: if args and argsn:
params = dict(args=args, **argsn) params = dict(args=args, **argsn)
@ -123,7 +123,7 @@ class AuthServiceProxy():
'id': AuthServiceProxy.__id_count} 'id': AuthServiceProxy.__id_count}
def __call__(self, *args, **argsn): 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')) response, status = self._request('POST', self.__url.path, postdata.encode('utf-8'))
if response['error'] is not None: if response['error'] is not None:
raise JSONRPCException(response['error'], status) raise JSONRPCException(response['error'], status)
@ -137,7 +137,7 @@ class AuthServiceProxy():
return response['result'] 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) postdata = json.dumps(list(rpc_call_list), default=serialization_fallback, ensure_ascii=self.ensure_ascii)
log.debug("--> " + postdata) log.debug("--> " + postdata)
response, status = self._request('POST', self.__url.path, postdata.encode('utf-8')) response, status = self._request('POST', self.__url.path, postdata.encode('utf-8'))
if status != HTTPStatus.OK: if status != HTTPStatus.OK:
@ -170,7 +170,7 @@ class AuthServiceProxy():
response = json.loads(responsedata, parse_float=decimal.Decimal) response = json.loads(responsedata, parse_float=decimal.Decimal)
elapsed = time.time() - req_start_time elapsed = time.time() - req_start_time
if "error" in response and response["error"] is None: 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: else:
log.debug("<-- [%.6f] %s" % (elapsed, responsedata)) log.debug("<-- [%.6f] %s" % (elapsed, responsedata))
return response, http_response.status return response, http_response.status

View File

@ -24,7 +24,7 @@ from pathlib import Path
from .authproxy import ( from .authproxy import (
JSONRPCException, JSONRPCException,
EncodeDecimal, serialization_fallback,
) )
from .descriptors import descsum_create from .descriptors import descsum_create
from .p2p import P2P_SUBVERSION from .p2p import P2P_SUBVERSION
@ -714,7 +714,7 @@ def arg_to_cli(arg):
elif arg is None: elif arg is None:
return 'null' return 'null'
elif isinstance(arg, dict) or isinstance(arg, list): elif isinstance(arg, dict) or isinstance(arg, list):
return json.dumps(arg, default=EncodeDecimal) return json.dumps(arg, default=serialization_fallback)
else: else:
return str(arg) return str(arg)