mirror of
https://github.com/django/django.git
synced 2025-06-05 11:39:13 +00:00
Made checks happy.
This commit is contained in:
parent
1abbd58bef
commit
92fea20839
@ -1,9 +1,7 @@
|
|||||||
import codecs
|
import codecs
|
||||||
import copy
|
import copy
|
||||||
import operator
|
import operator
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from cgi import parse_header
|
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
from urllib.parse import parse_qsl, quote, urlencode, urljoin, urlsplit
|
from urllib.parse import parse_qsl, quote, urlencode, urljoin, urlsplit
|
||||||
@ -18,10 +16,7 @@ from django.core.exceptions import (
|
|||||||
TooManyFieldsSent,
|
TooManyFieldsSent,
|
||||||
)
|
)
|
||||||
from django.core.files import uploadhandler
|
from django.core.files import uploadhandler
|
||||||
from django.http.multipartparser import (
|
from django.http.multipartparser import MultiPartParser, MultiPartParserError
|
||||||
MultiPartParser,
|
|
||||||
MultiPartParserError,
|
|
||||||
)
|
|
||||||
from django.utils.datastructures import (
|
from django.utils.datastructures import (
|
||||||
CaseInsensitiveMapping,
|
CaseInsensitiveMapping,
|
||||||
ImmutableList,
|
ImmutableList,
|
||||||
@ -29,7 +24,7 @@ from django.utils.datastructures import (
|
|||||||
)
|
)
|
||||||
from django.utils.encoding import escape_uri_path, iri_to_uri
|
from django.utils.encoding import escape_uri_path, iri_to_uri
|
||||||
from django.utils.functional import cached_property
|
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()
|
RAISE_ERROR = object()
|
||||||
MAX_ALLOWED_FILES = 1000
|
MAX_ALLOWED_FILES = 1000
|
||||||
@ -136,7 +131,7 @@ class HttpRequest:
|
|||||||
|
|
||||||
def _set_content_type_params(self, meta):
|
def _set_content_type_params(self, meta):
|
||||||
"""Set content_type, content_params, and encoding."""
|
"""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", "")
|
meta.get("CONTENT_TYPE", "")
|
||||||
)
|
)
|
||||||
if "charset" in self.content_params:
|
if "charset" in self.content_params:
|
||||||
@ -437,7 +432,8 @@ class HttpRequest:
|
|||||||
self._post, self._files = self.parse_file_upload(self.META, data)
|
self._post, self._files = self.parse_file_upload(self.META, data)
|
||||||
if len(self._files) > MAX_ALLOWED_FILES:
|
if len(self._files) > MAX_ALLOWED_FILES:
|
||||||
raise MultiPartParserError(
|
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:
|
except MultiPartParserError:
|
||||||
# An error occurred while parsing POST data. Since when
|
# An error occurred while parsing POST data. Since when
|
||||||
@ -721,7 +717,7 @@ class QueryDict(MultiValueDict):
|
|||||||
|
|
||||||
class MediaType:
|
class MediaType:
|
||||||
def __init__(self, media_type_raw_line):
|
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 ""
|
media_type_raw_line if media_type_raw_line else ""
|
||||||
)
|
)
|
||||||
self.main_type, _, self.sub_type = full_type.partition("/")
|
self.main_type, _, self.sub_type = full_type.partition("/")
|
||||||
|
@ -421,7 +421,8 @@ class RequestsTests(SimpleTestCase):
|
|||||||
|
|
||||||
def test_POST_multipart_with_content_length_zero(self):
|
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:
|
# According to:
|
||||||
# https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13
|
# https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13
|
||||||
@ -591,7 +592,10 @@ class RequestsTests(SimpleTestCase):
|
|||||||
"wsgi.input": FakePayload(),
|
"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):
|
with self.assertRaisesMessage(MultiPartParserError, msg):
|
||||||
request.POST
|
request.POST
|
||||||
|
|
||||||
@ -1001,7 +1005,10 @@ class HostValidationTests(SimpleTestCase):
|
|||||||
|
|
||||||
@override_settings(ALLOWED_HOSTS=[])
|
@override_settings(ALLOWED_HOSTS=[])
|
||||||
def test_get_host_suggestion_of_allowed_host(self):
|
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_invalid_host = "Invalid HTTP_HOST header: %r."
|
||||||
msg_suggestion = msg_invalid_host + " You may need to add %r to ALLOWED_HOSTS."
|
msg_suggestion = msg_invalid_host + " You may need to add %r to ALLOWED_HOSTS."
|
||||||
msg_suggestion2 = (
|
msg_suggestion2 = (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user