From 0b9281bec1de4ebab5972b8791ff965fab6fb1c0 Mon Sep 17 00:00:00 2001 From: Izalia Mae Date: Wed, 9 Nov 2022 04:35:57 -0500 Subject: [PATCH] make sure sub-dicts in DotDict are DotDict objects --- relay/misc.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/relay/misc.py b/relay/misc.py index 5d2f849..a800766 100644 --- a/relay/misc.py +++ b/relay/misc.py @@ -275,6 +275,12 @@ async def validate_signature(actor, http_request): class DotDict(dict): + def __init__(self, _data, **kwargs): + dict.__init__(self) + + self.update(_data, **kwargs) + + def __getattr__(self, k): try: return self[k] @@ -322,6 +328,19 @@ class DotDict(dict): return json.dumps(self, indent=indent) + def update(self, _data, **kwargs): + if isinstance(_data, dict): + for key, value in _data.items(): + self[key] = value + + elif isinstance(_data, (list, tuple, set)): + for key, value in _data: + self[key] = value + + for key, value in kwargs.items(): + self[key] = value + + class Message(DotDict): @classmethod def new_actor(cls, host, pubkey, description=None):