commit 8e5da39c171bc84c5ae37786d7dad198957a0d11 Author: juga0 juga@riseup.net Date: Sat Mar 21 13:11:46 2020 +0000
chg: resultdump: Use custom json encoder/decoder --- sbws/lib/resultdump.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/sbws/lib/resultdump.py b/sbws/lib/resultdump.py index f7ec55b..02952f9 100644 --- a/sbws/lib/resultdump.py +++ b/sbws/lib/resultdump.py @@ -12,6 +12,7 @@ from datetime import timedelta from enum import Enum from sbws.globals import RESULT_VERSION, fail_hard from sbws.util.filelock import DirectoryLock +from sbws.util.json import CustomEncoder, CustomDecoder from sbws.lib.relaylist import Relay from .. import settings
@@ -45,7 +46,9 @@ def load_result_file(fname, success_only=False): for line in fd: num_total += 1 try: - r = Result.from_dict(json.loads(line.strip())) + r = Result.from_dict( + json.loads(line.strip(), cls=CustomDecoder) + ) except json.decoder.JSONDecodeError: log.warning('Could not decode result %s', line.strip()) r = None @@ -416,7 +419,7 @@ class Result: 'Unknown result type {}'.format(d['type']))
def __str__(self): - return json.dumps(self.to_dict()) + return json.dumps(self.to_dict(), cls=CustomEncoder)
class ResultError(Result):