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).
This commit is contained in:
Jake Howard 2024-05-29 14:48:27 +01:00 committed by GitHub
parent 02dab94c7b
commit ff308a0604
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 61 additions and 72 deletions

View file

@ -203,7 +203,7 @@ A :class:`ResolverMatch` object can also be assigned to a triple::
One possible use of :func:`~django.urls.resolve` would be to test whether a
view would raise a ``Http404`` error before redirecting to it::
from urllib.parse import urlparse
from urllib.parse import urlsplit
from django.urls import resolve
from django.http import Http404, HttpResponseRedirect
@ -215,7 +215,7 @@ view would raise a ``Http404`` error before redirecting to it::
# modify the request and response as required, e.g. change locale
# and set corresponding locale cookie
view, args, kwargs = resolve(urlparse(next)[2])
view, args, kwargs = resolve(urlsplit(next).path)
kwargs["request"] = request
try:
view(*args, **kwargs)