summary refs log tree commit diff
diff options
context:
space:
mode:
authorPatrick Cloke <clokep@users.noreply.github.com>2020-07-28 10:28:59 -0400
committerGitHub <noreply@github.com>2020-07-28 10:28:59 -0400
commit2c1e1b153d7ca429b84c2cd0a2d657a066de8bc7 (patch)
tree5b4b1973fd5ad164999dd237a4f94f2267da2ae0
parentFix exit code for `check_line_terminators.sh` (#7970) (diff)
downloadsynapse-2c1e1b153d7ca429b84c2cd0a2d657a066de8bc7.tar.xz
Use the JSON module from the std library instead of simplejson. (#7936)
-rw-r--r--changelog.d/7936.misc1
-rw-r--r--synapse/__init__.py12
-rw-r--r--synapse/python_dependencies.py2
3 files changed, 14 insertions, 1 deletions
diff --git a/changelog.d/7936.misc b/changelog.d/7936.misc
new file mode 100644
index 0000000000..4304bbdd25
--- /dev/null
+++ b/changelog.d/7936.misc
@@ -0,0 +1 @@
+Switch to the JSON implementation from the standard library and bump the minimum version of the canonicaljson library to 1.2.0.
diff --git a/synapse/__init__.py b/synapse/__init__.py
index 83ce2ae6f4..72c93f6c48 100644
--- a/synapse/__init__.py
+++ b/synapse/__init__.py
@@ -17,6 +17,7 @@
 """ This is a reference implementation of a Matrix homeserver.
 """
 
+import json
 import os
 import sys
 
@@ -25,6 +26,9 @@ if sys.version_info < (3, 5):
     print("Synapse requires Python 3.5 or above.")
     sys.exit(1)
 
+# Twisted and canonicaljson will fail to import when this file is executed to
+# get the __version__ during a fresh install. That's OK and subsequent calls to
+# actually start Synapse will import these libraries fine.
 try:
     from twisted.internet import protocol
     from twisted.internet.protocol import Factory
@@ -36,6 +40,14 @@ try:
 except ImportError:
     pass
 
+# Use the standard library json implementation instead of simplejson.
+try:
+    from canonicaljson import set_json_library
+
+    set_json_library(json)
+except ImportError:
+    pass
+
 __version__ = "1.18.0rc2"
 
 if bool(os.environ.get("SYNAPSE_TEST_PATCH_LOG_CONTEXTS", False)):
diff --git a/synapse/python_dependencies.py b/synapse/python_dependencies.py
index 8cfcdb0573..abea2be4ef 100644
--- a/synapse/python_dependencies.py
+++ b/synapse/python_dependencies.py
@@ -43,7 +43,7 @@ REQUIREMENTS = [
     "jsonschema>=2.5.1",
     "frozendict>=1",
     "unpaddedbase64>=1.1.0",
-    "canonicaljson>=1.1.3",
+    "canonicaljson>=1.2.0",
     # we use the type definitions added in signedjson 1.1.
     "signedjson>=1.1.0",
     "pynacl>=1.2.1",