From ae93f8044e928366e857a4d5f247e0262ecbb369 Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Fri, 25 Jun 2021 02:37:01 +0200 Subject: [PATCH] [enh] teach YunoHost how to serialize Table objects --- moulinette/interfaces/cli.py | 4 ---- moulinette/utils/serialize.py | 5 +++++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/moulinette/interfaces/cli.py b/moulinette/interfaces/cli.py index 55fe9077..b2e586fc 100644 --- a/moulinette/interfaces/cli.py +++ b/moulinette/interfaces/cli.py @@ -512,10 +512,6 @@ class Interface(BaseInterface): import json from moulinette.utils.serialize import JSONExtendedEncoder - # retro compat situation - if isinstance(ret, Table): - ret = ret.data - print(json.dumps(ret, cls=JSONExtendedEncoder)) else: plain_print_dict(ret) diff --git a/moulinette/utils/serialize.py b/moulinette/utils/serialize.py index 345cb4d4..e8db29a4 100644 --- a/moulinette/utils/serialize.py +++ b/moulinette/utils/serialize.py @@ -2,6 +2,8 @@ import logging from json.encoder import JSONEncoder import datetime +from moulinette import Table + logger = logging.getLogger("moulinette.utils.serialize") @@ -36,6 +38,9 @@ class JSONExtendedEncoder(JSONEncoder): o = o.replace(tzinfo=pytz.utc) return o.isoformat() + if isinstance(o, Table): + return o.data + # Return the repr for object that json can't encode logger.warning( "cannot properly encode in JSON the object %s, " "returned repr is: %r",