From c1b312ff73e2c783eacf9788952a0af4f9765495 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Tue, 22 Jan 2019 20:36:11 +0000 Subject: [PATCH] Use urlsplit, not urlparse (#341) --- starlette/datastructures.py | 10 +++------- starlette/testclient.py | 6 ++---- tests/test_datastructures.py | 1 - 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/starlette/datastructures.py b/starlette/datastructures.py index 67e3d057..c9c3fbb0 100644 --- a/starlette/datastructures.py +++ b/starlette/datastructures.py @@ -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 diff --git a/starlette/testclient.py b/starlette/testclient.py index daac0700..6e5749ca 100644 --- a/starlette/testclient.py +++ b/starlette/testclient.py @@ -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] diff --git a/tests/test_datastructures.py b/tests/test_datastructures.py index bcf15359..c811bac9 100644 --- a/tests/test_datastructures.py +++ b/tests/test_datastructures.py @@ -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")