This repository was archived by the owner on Apr 26, 2024. It is now read-only.
File tree 3 files changed +20
-90
lines changed
3 files changed +20
-90
lines changed Original file line number Diff line number Diff line change @@ -158,9 +158,8 @@ jsonschema = ">=3.0.0"
158
158
immutabledict = " >=2.0"
159
159
# We require 2.1.0 or higher for type hints. Previous guard was >= 1.1.0
160
160
unpaddedbase64 = " >=2.1.0"
161
- # We require 1.5.0 to work around an issue when running against the C implementation of
162
- # frozendict: https://github.com/matrix-org/python-canonicaljson/issues/36
163
- canonicaljson = " ^1.5.0"
161
+ # We require 2.0.0 for immutabledict support.
162
+ canonicaljson = " ^2.0.0"
164
163
# we use the type definitions added in signedjson 1.1.
165
164
signedjson = " ^1.1.0"
166
165
# validating SSL certs for IP addresses requires service_identity 18.1.
Original file line number Diff line number Diff line change 17
17
""" This is an implementation of a Matrix homeserver.
18
18
"""
19
19
20
- import json
21
20
import os
22
21
import sys
22
+ from typing import Any , Dict
23
23
24
24
from synapse .util .rust import check_rust_lib_up_to_date
25
25
from synapse .util .stringutils import strtobool
61
61
except ImportError :
62
62
pass
63
63
64
- # Use the standard library json implementation instead of simplejson .
64
+ # Teach canonicaljson how to serialise immutabledicts .
65
65
try :
66
- from canonicaljson import set_json_library
67
-
68
- set_json_library (json )
66
+ from canonicaljson import register_preserialisation_callback
67
+ from immutabledict import immutabledict
68
+
69
+ def _immutabledict_cb (d : immutabledict ) -> Dict [str , Any ]:
70
+ try :
71
+ return d ._dict
72
+ except Exception :
73
+ # Paranoia: fall back to a `dict()` call, in case a future version of
74
+ # immutabledict removes `_dict` from the implementation.
75
+ return dict (d )
76
+
77
+ register_preserialisation_callback (immutabledict , _immutabledict_cb )
69
78
except ImportError :
70
79
pass
71
80
You can’t perform that action at this time.
0 commit comments