This repository was archived by the owner on Apr 26, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +20
-90
lines changed
Expand file tree Collapse file tree 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"
158158immutabledict = " >=2.0"
159159# We require 2.1.0 or higher for type hints. Previous guard was >= 1.1.0
160160unpaddedbase64 = " >=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"
164163# we use the type definitions added in signedjson 1.1.
165164signedjson = " ^1.1.0"
166165# validating SSL certs for IP addresses requires service_identity 18.1.
Original file line number Diff line number Diff line change 1717""" This is an implementation of a Matrix homeserver.
1818"""
1919
20- import json
2120import os
2221import sys
22+ from typing import Any , Dict
2323
2424from synapse .util .rust import check_rust_lib_up_to_date
2525from synapse .util .stringutils import strtobool
6161except ImportError :
6262 pass
6363
64- # Use the standard library json implementation instead of simplejson .
64+ # Teach canonicaljson how to serialise immutabledicts .
6565try :
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 )
6978except ImportError :
7079 pass
7180
You can’t perform that action at this time.
0 commit comments