summaryrefslogtreecommitdiff
path: root/django/test/testcases.py
diff options
context:
space:
mode:
authorJake Howard <RealOrangeOne@users.noreply.github.com>2024-05-29 14:48:27 +0100
committerGitHub <noreply@github.com>2024-05-29 10:48:27 -0300
commitff308a06047cd60806d604a7cf612e5656ee2ac9 (patch)
treef2139fbf020cbdf33bad64a3377700623c18a44f /django/test/testcases.py
parent02dab94c7b8585c7ae3854465574d768e1df75d3 (diff)
Fixed 35467 -- Replaced urlparse with urlsplit where appropriate.
This work should not generate any change of functionality, and `urlsplit` is approximately 6x faster. Most use cases of `urlparse` didn't touch the path, so they can be converted to `urlsplit` without any issue. Most of those which do use `.path`, simply parse the URL, mutate the querystring, then put them back together, which is also fine (so long as urlunsplit is used).
Diffstat (limited to 'django/test/testcases.py')
-rw-r--r--django/test/testcases.py12
1 files changed, 5 insertions, 7 deletions
diff --git a/django/test/testcases.py b/django/test/testcases.py
index 0a802c887b..f1c6b5ae9c 100644
--- a/django/test/testcases.py
+++ b/django/test/testcases.py
@@ -21,7 +21,7 @@ from urllib.parse import (
urljoin,
urlparse,
urlsplit,
- urlunparse,
+ urlunsplit,
)
from urllib.request import url2pathname
@@ -541,11 +541,9 @@ class SimpleTestCase(unittest.TestCase):
def normalize(url):
"""Sort the URL's query string parameters."""
url = str(url) # Coerce reverse_lazy() URLs.
- scheme, netloc, path, params, query, fragment = urlparse(url)
+ scheme, netloc, path, query, fragment = urlsplit(url)
query_parts = sorted(parse_qsl(query))
- return urlunparse(
- (scheme, netloc, path, params, urlencode(query_parts), fragment)
- )
+ return urlunsplit((scheme, netloc, path, urlencode(query_parts), fragment))
if msg_prefix:
msg_prefix += ": "
@@ -1637,11 +1635,11 @@ class FSFilesHandler(WSGIHandler):
* the host is provided as part of the base_url
* the request's path isn't under the media path (or equal)
"""
- return path.startswith(self.base_url[2]) and not self.base_url[1]
+ return path.startswith(self.base_url.path) and not self.base_url.netloc
def file_path(self, url):
"""Return the relative path to the file on disk for the given URL."""
- relative_url = url.removeprefix(self.base_url[2])
+ relative_url = url.removeprefix(self.base_url.path)
return url2pathname(relative_url)
def get_response(self, request):