summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-02-11 15:44:28 +0000
committerErik Johnston <erik@matrix.org>2015-02-11 15:44:28 +0000
commitddb816cf60ca1b0c0f9bfab5df233a010ac309a3 (patch)
treec3db58914617f2375c603f6c5d1eb8ca5d2600b2 /synapse
parentBlunty replace json with simplejson (diff)
downloadsynapse-ddb816cf60ca1b0c0f9bfab5df233a010ac309a3.tar.xz
Don't unfreeze when using FreezeEvent.get_dict, as we are using a JSONEncoder that understands FrozenDict
Diffstat (limited to '')
-rw-r--r--synapse/events/__init__.py4
-rw-r--r--synapse/federation/persistence.py7
-rw-r--r--synapse/handlers/federation.py15
-rw-r--r--synapse/handlers/room.py4
-rw-r--r--synapse/storage/__init__.py11
-rw-r--r--synapse/util/frozenutils.py8
6 files changed, 36 insertions, 13 deletions
diff --git a/synapse/events/__init__.py b/synapse/events/__init__.py
index 8f0c6e959f..f4ec8cd18c 100644
--- a/synapse/events/__init__.py
+++ b/synapse/events/__init__.py
@@ -140,10 +140,6 @@ class FrozenEvent(EventBase):
 
         return e
 
-    def get_dict(self):
-        # We need to unfreeze what we return
-        return unfreeze(super(FrozenEvent, self).get_dict())
-
     def __str__(self):
         return self.__repr__()
 
diff --git a/synapse/federation/persistence.py b/synapse/federation/persistence.py
index 8a1afc0ca5..76a9dcd777 100644
--- a/synapse/federation/persistence.py
+++ b/synapse/federation/persistence.py
@@ -23,7 +23,8 @@ from twisted.internet import defer
 
 from synapse.util.logutils import log_function
 
-import simplejson as json
+from syutil.jsonutil import encode_canonical_json
+
 import logging
 
 
@@ -70,7 +71,7 @@ class TransactionActions(object):
             transaction.transaction_id,
             transaction.origin,
             code,
-            json.dumps(response)
+            encode_canonical_json(response)
         )
 
     @defer.inlineCallbacks
@@ -100,5 +101,5 @@ class TransactionActions(object):
             transaction.transaction_id,
             transaction.destination,
             response_code,
-            json.dumps(response_dict)
+            encode_canonical_json(response_dict)
         )
diff --git a/synapse/handlers/federation.py b/synapse/handlers/federation.py
index 0f9c82fd06..e36f0945ef 100644
--- a/synapse/handlers/federation.py
+++ b/synapse/handlers/federation.py
@@ -23,6 +23,7 @@ from synapse.api.errors import (
 from synapse.api.constants import EventTypes, Membership, RejectedReason
 from synapse.util.logutils import log_function
 from synapse.util.async import run_on_reactor
+from synapse.util.frozenutils import unfreeze
 from synapse.crypto.event_signing import (
     compute_event_signature, add_hashes_and_signatures,
 )
@@ -311,9 +312,12 @@ class FederationHandler(BaseHandler):
         self.room_queues[room_id] = []
 
         builder = self.event_builder_factory.new(
-            event.get_pdu_json()
+            unfreeze(event.get_pdu_json())
         )
 
+        logger.info("Builder: %s", builder.get_pdu_json())
+        logger.info("Content: %s", content)
+
         handled_events = set()
 
         try:
@@ -324,14 +328,21 @@ class FederationHandler(BaseHandler):
             if not hasattr(event, "signatures"):
                 builder.signatures = {}
 
+            logger.info("Content befhahs: %s", builder.content)
+
             add_hashes_and_signatures(
                 builder,
                 self.hs.hostname,
                 self.hs.config.signing_key[0],
             )
 
+            logger.info("Content aftet hah: %s", builder.content)
+            logger.info("Content pdu json: %s", builder.get_pdu_json())
+
             new_event = builder.build()
 
+            logger.info("Content after build: %s", new_event.content)
+
             # Try the host we successfully got a response to /make_join/
             # request first.
             try:
@@ -340,6 +351,7 @@ class FederationHandler(BaseHandler):
             except ValueError:
                 pass
 
+            logger.info(new_event.content)
             ret = yield self.replication_layer.send_join(
                 target_hosts,
                 new_event
@@ -485,6 +497,7 @@ class FederationHandler(BaseHandler):
 
         event.internal_metadata.outlier = False
 
+        logger.info(event.content)
         context = yield self._handle_new_event(origin, event)
 
         logger.debug(
diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py
index 0369b907a5..c685991a9f 100644
--- a/synapse/handlers/room.py
+++ b/synapse/handlers/room.py
@@ -403,7 +403,9 @@ class RoomMemberHandler(BaseHandler):
             "membership": Membership.JOIN,
             "content": content,
         })
+        logger.info("Before build: %s", builder.get_pdu_json())
         event, context = yield self._create_new_client_event(builder)
+        logger.info("After build: %s", event.get_dict())
 
         yield self._do_join(event, context, room_hosts=hosts, do_auth=True)
 
@@ -462,7 +464,7 @@ class RoomMemberHandler(BaseHandler):
                 room_hosts,
                 room_id,
                 event.user_id,
-                event.get_dict()["content"],  # FIXME To get a non-frozen dict
+                event.content,  # FIXME To get a non-frozen dict
                 context
             )
         else:
diff --git a/synapse/storage/__init__.py b/synapse/storage/__init__.py
index 924ea89035..94603ef826 100644
--- a/synapse/storage/__init__.py
+++ b/synapse/storage/__init__.py
@@ -298,12 +298,16 @@ class DataStore(RoomMemberStore, RoomStore,
             or_replace=True,
         )
 
+        content = encode_canonical_json(
+            event.content
+        ).decode("UTF-8")
+
         vals = {
             "topological_ordering": event.depth,
             "event_id": event.event_id,
             "type": event.type,
             "room_id": event.room_id,
-            "content": json.dumps(event.get_dict()["content"]),
+            "content": content,
             "processed": True,
             "outlier": outlier,
             "depth": event.depth,
@@ -323,7 +327,10 @@ class DataStore(RoomMemberStore, RoomStore,
                 "prev_events",
             ]
         }
-        vals["unrecognized_keys"] = json.dumps(unrec)
+
+        vals["unrecognized_keys"] = encode_canonical_json(
+            unrec
+        ).decode("UTF-8")
 
         try:
             self._simple_insert_txn(
diff --git a/synapse/util/frozenutils.py b/synapse/util/frozenutils.py
index a13a2015e4..9e10d37aec 100644
--- a/synapse/util/frozenutils.py
+++ b/synapse/util/frozenutils.py
@@ -21,6 +21,9 @@ def freeze(o):
     if t is dict:
         return frozendict({k: freeze(v) for k, v in o.items()})
 
+    if t is frozendict:
+        return o
+
     if t is str or t is unicode:
         return o
 
@@ -33,10 +36,11 @@ def freeze(o):
 
 
 def unfreeze(o):
-    if isinstance(o, frozendict) or isinstance(o, dict):
+    t = type(o)
+    if t is dict or t is frozendict:
         return dict({k: unfreeze(v) for k, v in o.items()})
 
-    if isinstance(o, basestring):
+    if t is str or t is unicode:
         return o
 
     try: