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

Commit fe604a0

Browse files
Remove various bits of compatibility code for Python <3.6 (#9879)
I went through and removed a bunch of cruft that was lying around for compatibility with old Python versions. This PR also will now prevent Synapse from starting unless you're running Python 3.6+.
1 parent 1350b05 commit fe604a0

File tree

16 files changed

+29
-98
lines changed

16 files changed

+29
-98
lines changed

changelog.d/9879.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove backwards-compatibility code for Python versions < 3.6.

mypy.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ files =
4141
synapse/push,
4242
synapse/replication,
4343
synapse/rest,
44-
synapse/secrets.py,
4544
synapse/server.py,
4645
synapse/server_notices,
4746
synapse/spam_checker_api,

synapse/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import sys
2222

2323
# Check that we're not running on an unsupported Python version.
24-
if sys.version_info < (3, 5):
25-
print("Synapse requires Python 3.5 or above.")
24+
if sys.version_info < (3, 6):
25+
print("Synapse requires Python 3.6 or above.")
2626
sys.exit(1)
2727

2828
# Twisted and canonicaljson will fail to import when this file is executed to

synapse/python_dependencies.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
"typing-extensions>=3.7.4",
8686
# We enforce that we have a `cryptography` version that bundles an `openssl`
8787
# with the latest security patches.
88-
"cryptography>=3.4.7;python_version>='3.6'",
88+
"cryptography>=3.4.7",
8989
]
9090

9191
CONDITIONAL_REQUIREMENTS = {
@@ -100,14 +100,9 @@
100100
# that use the protocol, such as Let's Encrypt.
101101
"acme": [
102102
"txacme>=0.9.2",
103-
# txacme depends on eliot. Eliot 1.8.0 is incompatible with
104-
# python 3.5.2, as per https://github.com/itamarst/eliot/issues/418
105-
"eliot<1.8.0;python_version<'3.5.3'",
106103
],
107104
"saml2": [
108-
# pysaml2 6.4.0 is incompatible with Python 3.5 (see https://github.com/IdentityPython/pysaml2/issues/749)
109-
"pysaml2>=4.5.0,<6.4.0;python_version<'3.6'",
110-
"pysaml2>=4.5.0;python_version>='3.6'",
105+
"pysaml2>=4.5.0",
111106
],
112107
"oidc": ["authlib>=0.14.0"],
113108
# systemd-python is necessary for logging to the systemd journal via

synapse/rest/admin/users.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import hashlib
1515
import hmac
1616
import logging
17+
import secrets
1718
from http import HTTPStatus
1819
from typing import TYPE_CHECKING, Dict, List, Optional, Tuple
1920

@@ -375,7 +376,7 @@ def on_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
375376
"""
376377
self._clear_old_nonces()
377378

378-
nonce = self.hs.get_secrets().token_hex(64)
379+
nonce = secrets.token_hex(64)
379380
self.nonces[nonce] = int(self.reactor.seconds())
380381
return 200, {"nonce": nonce}
381382

synapse/rest/consent/consent_resource.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,6 @@
3232

3333
logger = logging.getLogger(__name__)
3434

35-
# use hmac.compare_digest if we have it (python 2.7.7), else just use equality
36-
if hasattr(hmac, "compare_digest"):
37-
compare_digest = hmac.compare_digest
38-
else:
39-
40-
def compare_digest(a, b):
41-
return a == b
42-
4335

4436
class ConsentResource(DirectServeHtmlResource):
4537
"""A twisted Resource to display a privacy policy and gather consent to it
@@ -209,5 +201,5 @@ def _check_hash(self, userid, userhmac):
209201
.encode("ascii")
210202
)
211203

212-
if not compare_digest(want_mac, userhmac):
204+
if not hmac.compare_digest(want_mac, userhmac):
213205
raise SynapseError(HTTPStatus.FORBIDDEN, "HMAC incorrect")

synapse/rest/media/v1/filepath.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
NEW_FORMAT_ID_RE = re.compile(r"^\d\d\d\d-\d\d-\d\d")
2222

2323

24-
def _wrap_in_base_path(func: "Callable[..., str]") -> "Callable[..., str]":
24+
def _wrap_in_base_path(func: Callable[..., str]) -> Callable[..., str]:
2525
"""Takes a function that returns a relative path and turns it into an
2626
absolute path based on the location of the primary media store
2727
"""

synapse/secrets.py

Lines changed: 0 additions & 44 deletions
This file was deleted.

synapse/server.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@
126126
MediaRepository,
127127
MediaRepositoryResource,
128128
)
129-
from synapse.secrets import Secrets
130129
from synapse.server_notices.server_notices_manager import ServerNoticesManager
131130
from synapse.server_notices.server_notices_sender import ServerNoticesSender
132131
from synapse.server_notices.worker_server_notices_sender import (
@@ -641,10 +640,6 @@ def get_groups_attestation_signing(self) -> GroupAttestationSigning:
641640
def get_groups_attestation_renewer(self) -> GroupAttestionRenewer:
642641
return GroupAttestionRenewer(self)
643642

644-
@cache_in_self
645-
def get_secrets(self) -> Secrets:
646-
return Secrets()
647-
648643
@cache_in_self
649644
def get_stats_handler(self) -> StatsHandler:
650645
return StatsHandler(self)

synapse/storage/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def db_to_json(db_content: Union[memoryview, bytes, bytearray, str]) -> Any:
114114
db_content = db_content.tobytes()
115115

116116
# Decode it to a Unicode string before feeding it to the JSON decoder, since
117-
# Python 3.5 does not support deserializing bytes.
117+
# it only supports handling strings
118118
if isinstance(db_content, (bytes, bytearray)):
119119
db_content = db_content.decode("utf8")
120120

0 commit comments

Comments
 (0)