Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Use new canonicaljson serisalistion hook
Browse files Browse the repository at this point in the history
  • Loading branch information
David Robertson committed Mar 15, 2023
1 parent 3537e5c commit 07b3168
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 86 deletions.
86 changes: 4 additions & 82 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,8 @@ jsonschema = ">=3.0.0"
immutabledict = ">=2.0"
# We require 2.1.0 or higher for type hints. Previous guard was >= 1.1.0
unpaddedbase64 = ">=2.1.0"
# We require 1.5.0 to work around an issue when running against the C implementation of
# frozendict: https://github.com/matrix-org/python-canonicaljson/issues/36
canonicaljson = "^1.5.0"
# We require 2.0.0 for immutabledict support.
canonicaljson = "^2.0.0"
# we use the type definitions added in signedjson 1.1.
signedjson = "^1.1.0"
# validating SSL certs for IP addresses requires service_identity 18.1.
Expand Down
9 changes: 8 additions & 1 deletion synapse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import json
import os
import sys
from typing import Any, Dict

from synapse.util.rust import check_rust_lib_up_to_date
from synapse.util.stringutils import strtobool
Expand Down Expand Up @@ -63,9 +64,15 @@

# Use the standard library json implementation instead of simplejson.
try:
from canonicaljson import set_json_library
from canonicaljson import register_preserialisation_callback, set_json_library
from immutabledict import immutabledict

set_json_library(json)

def _immutabledict_cb(d: immutabledict) -> Dict[str, Any]:
return d._dict

register_preserialisation_callback(immutabledict, _immutabledict_cb)
except ImportError:
pass

Expand Down

0 comments on commit 07b3168

Please sign in to comment.