mirror of
https://mau.dev/maunium/synapse.git
synced 2024-09-04 08:32:29 +00:00
Use frozenutils
This commit is contained in:
parent
009e4b5637
commit
f280929a12
@ -15,39 +15,11 @@
|
|||||||
|
|
||||||
from frozendict import frozendict
|
from frozendict import frozendict
|
||||||
|
|
||||||
|
from synapse.util.frozenutils import freeze, unfreeze
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
|
|
||||||
def _freeze(o):
|
|
||||||
if isinstance(o, dict) or isinstance(o, frozendict):
|
|
||||||
return frozendict({k: _freeze(v) for k, v in o.items()})
|
|
||||||
|
|
||||||
if isinstance(o, basestring):
|
|
||||||
return o
|
|
||||||
|
|
||||||
try:
|
|
||||||
return tuple([_freeze(i) for i in o])
|
|
||||||
except TypeError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
return o
|
|
||||||
|
|
||||||
|
|
||||||
def _unfreeze(o):
|
|
||||||
if isinstance(o, frozendict) or isinstance(o, dict):
|
|
||||||
return dict({k: _unfreeze(v) for k, v in o.items()})
|
|
||||||
|
|
||||||
if isinstance(o, basestring):
|
|
||||||
return o
|
|
||||||
|
|
||||||
try:
|
|
||||||
return [_unfreeze(i) for i in o]
|
|
||||||
except TypeError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
return o
|
|
||||||
|
|
||||||
|
|
||||||
class _EventInternalMetadata(object):
|
class _EventInternalMetadata(object):
|
||||||
def __init__(self, internal_metadata_dict):
|
def __init__(self, internal_metadata_dict):
|
||||||
self.__dict__ = copy.deepcopy(internal_metadata_dict)
|
self.__dict__ = copy.deepcopy(internal_metadata_dict)
|
||||||
@ -147,7 +119,7 @@ class FrozenEvent(EventBase):
|
|||||||
signatures = copy.deepcopy(event_dict.pop("signatures", {}))
|
signatures = copy.deepcopy(event_dict.pop("signatures", {}))
|
||||||
unsigned = copy.deepcopy(event_dict.pop("unsigned", {}))
|
unsigned = copy.deepcopy(event_dict.pop("unsigned", {}))
|
||||||
|
|
||||||
frozen_dict = _freeze(event_dict)
|
frozen_dict = freeze(event_dict)
|
||||||
|
|
||||||
super(FrozenEvent, self).__init__(
|
super(FrozenEvent, self).__init__(
|
||||||
frozen_dict,
|
frozen_dict,
|
||||||
@ -167,7 +139,7 @@ class FrozenEvent(EventBase):
|
|||||||
|
|
||||||
def get_dict(self):
|
def get_dict(self):
|
||||||
# We need to unfreeze what we return
|
# We need to unfreeze what we return
|
||||||
return _unfreeze(super(FrozenEvent, self).get_dict())
|
return unfreeze(super(FrozenEvent, self).get_dict())
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.__repr__()
|
return self.__repr__()
|
||||||
|
@ -21,7 +21,6 @@ from synapse.api.events.room import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from synapse.util.logutils import log_function
|
from synapse.util.logutils import log_function
|
||||||
from synapse.util.frozenutils import FrozenEncoder
|
|
||||||
|
|
||||||
from .directory import DirectoryStore
|
from .directory import DirectoryStore
|
||||||
from .feedback import FeedbackStore
|
from .feedback import FeedbackStore
|
||||||
@ -177,7 +176,7 @@ class DataStore(RoomMemberStore, RoomStore,
|
|||||||
"event_id": event.event_id,
|
"event_id": event.event_id,
|
||||||
"type": event.type,
|
"type": event.type,
|
||||||
"room_id": event.room_id,
|
"room_id": event.room_id,
|
||||||
"content": json.dumps(event.content, cls=FrozenEncoder),
|
"content": json.dumps(event.get_dict()["content"]),
|
||||||
"processed": True,
|
"processed": True,
|
||||||
"outlier": outlier,
|
"outlier": outlier,
|
||||||
"depth": event.depth,
|
"depth": event.depth,
|
||||||
|
Loading…
Reference in New Issue
Block a user