From 27fea36e488e61349501f6a486cc06051695116f Mon Sep 17 00:00:00 2001 From: Reid 'arrdem' McKenzie Date: Sat, 26 Nov 2022 22:51:31 -0700 Subject: [PATCH] jsonify the config object --- projects/activitypub_relay/src/python/relay/config.py | 3 ++- projects/activitypub_relay/src/python/relay/misc.py | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/projects/activitypub_relay/src/python/relay/config.py b/projects/activitypub_relay/src/python/relay/config.py index e43e90d..3560f5f 100644 --- a/projects/activitypub_relay/src/python/relay/config.py +++ b/projects/activitypub_relay/src/python/relay/config.py @@ -198,4 +198,5 @@ class RelayConfig(DotDict): def save(self): with open(self._path, "w") as fd: - yaml.dump(self, fd, sort_keys=False) + fd.write("---\n") + yaml.dump(self.jsonify(), fd, sort_keys=True) diff --git a/projects/activitypub_relay/src/python/relay/misc.py b/projects/activitypub_relay/src/python/relay/misc.py index 412185f..5868ed1 100644 --- a/projects/activitypub_relay/src/python/relay/misc.py +++ b/projects/activitypub_relay/src/python/relay/misc.py @@ -328,6 +328,15 @@ class DotDict(dict): def to_json(self, indent=None): return json.dumps(self, indent=indent) + def jsonify(self): + def _xform(v): + if hasattr(v, 'jsonify'): + return v.jsonify() + else: + return v + + return {k: _xform(v) for k, v in self.items()} + def update(self, _data, **kwargs): if isinstance(_data, dict): for key, value in _data.items():