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