diff --git a/django/http/request.py b/django/http/request.py index 958cedfdbf..b718b09561 100644 --- a/django/http/request.py +++ b/django/http/request.py @@ -1,9 +1,7 @@ import codecs import copy import operator - from collections import namedtuple -from cgi import parse_header from io import BytesIO from itertools import chain from urllib.parse import parse_qsl, quote, urlencode, urljoin, urlsplit @@ -18,10 +16,7 @@ from django.core.exceptions import ( TooManyFieldsSent, ) from django.core.files import uploadhandler -from django.http.multipartparser import ( - MultiPartParser, - MultiPartParserError, -) +from django.http.multipartparser import MultiPartParser, MultiPartParserError from django.utils.datastructures import ( CaseInsensitiveMapping, ImmutableList, @@ -29,7 +24,7 @@ from django.utils.datastructures import ( ) from django.utils.encoding import escape_uri_path, iri_to_uri from django.utils.functional import cached_property -from django.utils.http import is_same_domain +from django.utils.http import is_same_domain, parse_header_parameters RAISE_ERROR = object() MAX_ALLOWED_FILES = 1000 @@ -136,7 +131,7 @@ class HttpRequest: def _set_content_type_params(self, meta): """Set content_type, content_params, and encoding.""" - self.content_type, self.content_params = parse_header( + self.content_type, self.content_params = parse_header_parameters( meta.get("CONTENT_TYPE", "") ) if "charset" in self.content_params: @@ -437,7 +432,8 @@ class HttpRequest: self._post, self._files = self.parse_file_upload(self.META, data) if len(self._files) > MAX_ALLOWED_FILES: raise MultiPartParserError( - f"{len(self._files)} files processed. Maximum {MAX_ALLOWED_FILES} files allowed." + f"{len(self._files)} files processed. " + f"Maximum {MAX_ALLOWED_FILES} files allowed." ) except MultiPartParserError: # An error occurred while parsing POST data. Since when @@ -721,7 +717,7 @@ class QueryDict(MultiValueDict): class MediaType: def __init__(self, media_type_raw_line): - full_type, self.params = parse_header( + full_type, self.params = parse_header_parameters( media_type_raw_line if media_type_raw_line else "" ) self.main_type, _, self.sub_type = full_type.partition("/") diff --git a/tests/requests/tests.py b/tests/requests/tests.py index 90e024afa1..71efc4f57e 100644 --- a/tests/requests/tests.py +++ b/tests/requests/tests.py @@ -421,7 +421,8 @@ class RequestsTests(SimpleTestCase): def test_POST_multipart_with_content_length_zero(self): """ - Multipart POST requests with Content-Length >= 0 are valid and need to be handled. + Multipart POST requests with Content-Length >= 0 + are valid and need to be handled. """ # According to: # https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13 @@ -591,7 +592,10 @@ class RequestsTests(SimpleTestCase): "wsgi.input": FakePayload(), } ) - msg = "Invalid non-ASCII Content-Type in multipart: multipart/form-data; boundary = à" + msg = ( + "Invalid non-ASCII Content-Type in multipart: " + "multipart/form-data; boundary = à" + ) with self.assertRaisesMessage(MultiPartParserError, msg): request.POST @@ -1001,7 +1005,10 @@ class HostValidationTests(SimpleTestCase): @override_settings(ALLOWED_HOSTS=[]) def test_get_host_suggestion_of_allowed_host(self): - """get_host() makes helpful suggestions if a valid-looking host is not in ALLOWED_HOSTS.""" + """ + get_host() makes helpful suggestions + if a valid-looking host is not in ALLOWED_HOSTS. + """ msg_invalid_host = "Invalid HTTP_HOST header: %r." msg_suggestion = msg_invalid_host + " You may need to add %r to ALLOWED_HOSTS." msg_suggestion2 = (