make sure sub-dicts in DotDict are DotDict objects

This commit is contained in:
Izalia Mae 2022-11-09 04:35:57 -05:00
parent 76476d1d03
commit 0b9281bec1

View file

@ -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):