Skip to content

Commit 2fc43e4

Browse files
V02460sandhose
andauthored
Remove the deprecated cgi module (#17741)
Removes all uses of the `cgi` module from Synapse. It was deprecated in Python version 3.11 and removed in version 3.13 ([“dead battery”](https://docs.python.org/3.13/whatsnew/3.13.html#pep-594-remove-dead-batteries-from-the-standard-library)). ### Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [x] Pull request is based on the develop branch * [x] Pull request includes a [changelog file](https://element-hq.github.io/synapse/latest/development/contributing_guide.html#changelog). The entry should: - Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from `EventStore` to `EventWorkerStore`.". - Use markdown where necessary, mostly for `code blocks`. - End with either a period (.) or an exclamation mark (!). - Start with a capital letter. - Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry. * [x] [Code style](https://element-hq.github.io/synapse/latest/code_style.html) is correct (run the [linters](https://element-hq.github.io/synapse/latest/development/contributing_guide.html#run-the-linters)) --------- Co-authored-by: Quentin Gliech <[email protected]>
1 parent b0d2aca commit 2fc43e4

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

changelog.d/17741.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove usage of the deprecated cgi module.

contrib/graph/graph.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
#
2121

2222
import argparse
23-
import cgi
2423
import datetime
24+
import html
2525
import json
2626
import urllib.request
2727
from typing import List
@@ -85,7 +85,7 @@ def make_graph(pdus: List[dict], filename_prefix: str) -> None:
8585
"name": name,
8686
"type": pdu.get("pdu_type"),
8787
"state_key": pdu.get("state_key"),
88-
"content": cgi.escape(json.dumps(pdu.get("content")), quote=True),
88+
"content": html.escape(json.dumps(pdu.get("content")), quote=True),
8989
"time": t,
9090
"depth": pdu.get("depth"),
9191
}

synapse/http/matrixfederationclient.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#
2020
#
2121
import abc
22-
import cgi
2322
import codecs
2423
import logging
2524
import random
@@ -1813,8 +1812,9 @@ def check_content_type_is(headers: Headers, expected_content_type: str) -> None:
18131812
)
18141813

18151814
c_type = content_type_headers[0].decode("ascii") # only the first header
1816-
val, options = cgi.parse_header(c_type)
1817-
if val != expected_content_type:
1815+
# Extract the 'essence' of the mimetype, removing any parameter
1816+
c_type_parsed = c_type.split(";", 1)[0].strip()
1817+
if c_type_parsed != expected_content_type:
18181818
raise RequestSendFailed(
18191819
RuntimeError(
18201820
f"Remote server sent Content-Type header of '{c_type}', not '{expected_content_type}'",

0 commit comments

Comments
 (0)