From f9ffd6239bc339c2a47bd196406212f3aadc667a Mon Sep 17 00:00:00 2001 From: Marcelo Trylesinski Date: Sun, 27 Oct 2024 09:11:05 +0100 Subject: [PATCH] Revert bump on `python-multipart` (#2737) --- pyproject.toml | 2 +- starlette/formparsers.py | 21 +++++++++++++-------- starlette/requests.py | 16 ++++++++++------ 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 0dde83c72..a532e4628 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,7 +35,7 @@ dependencies = [ full = [ "itsdangerous", "jinja2", - "python-multipart>=0.0.13", + "python-multipart>=0.0.7", "pyyaml", "httpx>=0.22.0", ] diff --git a/starlette/formparsers.py b/starlette/formparsers.py index 2817a7b6c..82e2ad195 100644 --- a/starlette/formparsers.py +++ b/starlette/formparsers.py @@ -8,15 +8,20 @@ from starlette.datastructures import FormData, Headers, UploadFile -try: - import python_multipart as multipart - from python_multipart.multipart import parse_options_header -except ModuleNotFoundError: # pragma: no cover - parse_options_header = None # type: ignore - multipart = None # type: ignore - if typing.TYPE_CHECKING: - from python_multipart.multipart import MultipartCallbacks, QuerystringCallbacks + import multipart + from multipart.multipart import MultipartCallbacks, QuerystringCallbacks, parse_options_header +else: + try: + try: + import python_multipart as multipart + from python_multipart.multipart import parse_options_header + except ModuleNotFoundError: # pragma: no cover + import multipart + from multipart.multipart import parse_options_header + except ModuleNotFoundError: # pragma: no cover + multipart = None + parse_options_header = None class FormMessage(Enum): diff --git a/starlette/requests.py b/starlette/requests.py index 8decb2076..a29164d0d 100644 --- a/starlette/requests.py +++ b/starlette/requests.py @@ -12,15 +12,19 @@ from starlette.formparsers import FormParser, MultiPartException, MultiPartParser from starlette.types import Message, Receive, Scope, Send -try: - from python_multipart.multipart import parse_options_header -except ModuleNotFoundError: # pragma: no cover - parse_options_header = None # type: ignore - - if typing.TYPE_CHECKING: + from multipart.multipart import parse_options_header + from starlette.applications import Starlette from starlette.routing import Router +else: + try: + try: + from python_multipart.multipart import parse_options_header + except ModuleNotFoundError: # pragma: no cover + from multipart.multipart import parse_options_header + except ModuleNotFoundError: # pragma: no cover + parse_options_header = None SERVER_PUSH_HEADERS_TO_COPY = {