From a6dfd713e48b06f6bf8ef4d82694f8587b489139 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 30 Sep 2024 11:06:21 +0000 Subject: [PATCH 1/3] Bump python-multipart from 0.0.10 to 0.0.12 Bumps [python-multipart](https://github.com/Kludex/python-multipart) from 0.0.10 to 0.0.12. - [Release notes](https://github.com/Kludex/python-multipart/releases) - [Changelog](https://github.com/Kludex/python-multipart/blob/master/CHANGELOG.md) - [Commits](https://github.com/Kludex/python-multipart/compare/0.0.10...0.0.12) --- updated-dependencies: - dependency-name: python-multipart dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- poetry.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/poetry.lock b/poetry.lock index 0f2ee8cac05..0700767fbb9 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1974,13 +1974,13 @@ six = ">=1.5" [[package]] name = "python-multipart" -version = "0.0.10" +version = "0.0.12" description = "A streaming multipart parser for Python" optional = false python-versions = ">=3.8" files = [ - {file = "python_multipart-0.0.10-py3-none-any.whl", hash = "sha256:2b06ad9e8d50c7a8db80e3b56dab590137b323410605af2be20d62a5f1ba1dc8"}, - {file = "python_multipart-0.0.10.tar.gz", hash = "sha256:46eb3c6ce6fdda5fb1a03c7e11d490e407c6930a2703fe7aef4da71c374688fa"}, + {file = "python_multipart-0.0.12-py3-none-any.whl", hash = "sha256:43dcf96cf65888a9cd3423544dd0d75ac10f7aa0c3c28a175bbcd00c9ce1aebf"}, + {file = "python_multipart-0.0.12.tar.gz", hash = "sha256:045e1f98d719c1ce085ed7f7e1ef9d8ccc8c02ba02b5566d5f7521410ced58cb"}, ] [[package]] From f1791e628fd3157e179a9034a3ff0269abbdfc15 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Mon, 7 Oct 2024 09:03:45 +0100 Subject: [PATCH 2/3] Fix liniting --- synapse/http/client.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/synapse/http/client.py b/synapse/http/client.py index 143fee97964..f6d31203e95 100644 --- a/synapse/http/client.py +++ b/synapse/http/client.py @@ -1039,7 +1039,7 @@ def __init__( self.deferred = deferred self.boundary = boundary self.max_length = max_length - self.parser = None + self.parser: Optional[multipart.MultipartParser] = None self.multipart_response = MultipartResponse() self.has_redirect = False self.in_json = False @@ -1097,12 +1097,14 @@ def on_part_data(data: bytes, start: int, end: int) -> None: self.deferred.errback() self.file_length += end - start - callbacks = { - "on_header_field": on_header_field, - "on_header_value": on_header_value, - "on_part_data": on_part_data, - } - self.parser = multipart.MultipartParser(self.boundary, callbacks) + self.parser = multipart.MultipartParser( + boundary=self.boundary, + callbacks={ + "on_header_field": on_header_field, + "on_header_value": on_header_value, + "on_part_data": on_part_data, + }, + ) self.total_length += len(incoming_data) if self.max_length is not None and self.total_length >= self.max_length: @@ -1113,7 +1115,7 @@ def on_part_data(data: bytes, start: int, end: int) -> None: self.transport.abortConnection() try: - self.parser.write(incoming_data) # type: ignore[attr-defined] + self.parser.write(incoming_data) except Exception as e: logger.warning(f"Exception writing to multipart parser: {e}") self.deferred.errback() From 8ed3a4d1701743aea806073344ea4f415e67781f Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Mon, 7 Oct 2024 09:05:34 +0100 Subject: [PATCH 3/3] Fix up better --- synapse/http/client.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/synapse/http/client.py b/synapse/http/client.py index f6d31203e95..c3b2299c954 100644 --- a/synapse/http/client.py +++ b/synapse/http/client.py @@ -1097,14 +1097,12 @@ def on_part_data(data: bytes, start: int, end: int) -> None: self.deferred.errback() self.file_length += end - start - self.parser = multipart.MultipartParser( - boundary=self.boundary, - callbacks={ - "on_header_field": on_header_field, - "on_header_value": on_header_value, - "on_part_data": on_part_data, - }, - ) + callbacks: "multipart.multipart.MultipartCallbacks" = { + "on_header_field": on_header_field, + "on_header_value": on_header_value, + "on_part_data": on_part_data, + } + self.parser = multipart.MultipartParser(self.boundary, callbacks) self.total_length += len(incoming_data) if self.max_length is not None and self.total_length >= self.max_length: