mirror of https://github.com/encode/starlette.git
Use urlsplit, not urlparse (#341)
This commit is contained in:
parent
10b61f6cc2
commit
c1b312ff73
|
@ -3,7 +3,7 @@ import typing
|
|||
from collections import namedtuple
|
||||
from collections.abc import Sequence
|
||||
from shlex import shlex
|
||||
from urllib.parse import ParseResult, parse_qsl, urlencode, urlparse
|
||||
from urllib.parse import SplitResult, parse_qsl, urlencode, urlsplit
|
||||
|
||||
from starlette.concurrency import run_in_threadpool
|
||||
from starlette.types import Scope
|
||||
|
@ -50,9 +50,9 @@ class URL:
|
|||
self._url = url
|
||||
|
||||
@property
|
||||
def components(self) -> ParseResult:
|
||||
def components(self) -> SplitResult:
|
||||
if not hasattr(self, "_components"):
|
||||
self._components = urlparse(self._url)
|
||||
self._components = urlsplit(self._url)
|
||||
return self._components
|
||||
|
||||
@property
|
||||
|
@ -67,10 +67,6 @@ class URL:
|
|||
def path(self) -> str:
|
||||
return self.components.path
|
||||
|
||||
@property
|
||||
def params(self) -> str:
|
||||
return self.components.params
|
||||
|
||||
@property
|
||||
def query(self) -> str:
|
||||
return self.components.query
|
||||
|
|
|
@ -6,7 +6,7 @@ import queue
|
|||
import threading
|
||||
import types
|
||||
import typing
|
||||
from urllib.parse import unquote, urljoin, urlparse
|
||||
from urllib.parse import unquote, urljoin, urlsplit
|
||||
|
||||
import requests
|
||||
|
||||
|
@ -67,9 +67,7 @@ class _ASGIAdapter(requests.adapters.HTTPAdapter):
|
|||
def send( # type: ignore
|
||||
self, request: requests.PreparedRequest, *args: typing.Any, **kwargs: typing.Any
|
||||
) -> requests.Response:
|
||||
scheme, netloc, path, params, query, fragement = urlparse( # type: ignore
|
||||
request.url
|
||||
)
|
||||
scheme, netloc, path, query, fragement = urlsplit(request.url) # type: ignore
|
||||
|
||||
default_port = {"http": 80, "ws": 80, "https": 443, "wss": 443}[scheme]
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ def test_url():
|
|||
assert u.password is None
|
||||
assert u.path == "/path/to/somewhere"
|
||||
assert u.query == "abc=123"
|
||||
assert u.params == ""
|
||||
assert u.fragment == "anchor"
|
||||
|
||||
new = u.replace(scheme="http")
|
||||
|
|
Loading…
Reference in New Issue