From: Tom Christie Date: Thu, 16 May 2019 09:56:05 +0000 (+0100) Subject: Drop unused interface on ConnectionStore (#70) X-Git-Tag: 0.3.0~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3ed08857eec8b6bfcf8b8f6c1c696fafd3bd6b95;p=thirdparty%2Fhttpx.git Drop unused interface on ConnectionStore (#70) --- diff --git a/httpcore/dispatch/connection_pool.py b/httpcore/dispatch/connection_pool.py index e0fb642e..ba92acd0 100644 --- a/httpcore/dispatch/connection_pool.py +++ b/httpcore/dispatch/connection_pool.py @@ -1,4 +1,3 @@ -import collections.abc import typing from ..concurrency import AsyncioBackend @@ -20,7 +19,7 @@ from .connection import HTTPConnection CONNECTIONS_DICT = typing.Dict[Origin, typing.List[HTTPConnection]] -class ConnectionStore(collections.abc.Sequence): +class ConnectionStore: """ We need to maintain collections of connections in a way that allows us to: @@ -74,11 +73,6 @@ class ConnectionStore(collections.abc.Sequence): def __iter__(self) -> typing.Iterator[HTTPConnection]: return iter(self.all.keys()) - def __getitem__(self, key: typing.Any) -> typing.Any: - if key in self.all: - return key - return None - def __len__(self) -> int: return len(self.all) diff --git a/httpcore/models.py b/httpcore/models.py index 663b6400..ea26fa4c 100644 --- a/httpcore/models.py +++ b/httpcore/models.py @@ -45,7 +45,7 @@ HeaderTypes = typing.Union[ AuthTypes = typing.Union[ typing.Tuple[typing.Union[str, bytes], typing.Union[str, bytes]], - typing.Callable[["Request"], "Request"] + typing.Callable[["Request"], "Request"], ] RequestData = typing.Union[dict, bytes, typing.AsyncIterator[bytes]] @@ -101,12 +101,12 @@ class URL: @property def username(self) -> str: userinfo = self.components.userinfo or "" - return userinfo.partition(':')[0] + return userinfo.partition(":")[0] @property def password(self) -> str: userinfo = self.components.userinfo or "" - return userinfo.partition(':')[2] + return userinfo.partition(":")[2] @property def host(self) -> str: diff --git a/tests/client/test_auth.py b/tests/client/test_auth.py index e044acd8..6e4db0c5 100644 --- a/tests/client/test_auth.py +++ b/tests/client/test_auth.py @@ -1,5 +1,4 @@ import json -from urllib.parse import parse_qs import pytest @@ -22,19 +21,21 @@ class MockDispatch(Dispatcher): ssl: SSLConfig = None, timeout: TimeoutConfig = None, ) -> Response: - body = json.dumps({"auth": request.headers.get('Authorization')}).encode() + body = json.dumps({"auth": request.headers.get("Authorization")}).encode() return Response(200, content=body, request=request) def test_basic_auth(): url = "https://example.org/" - auth = ('tomchristie', 'password123') + auth = ("tomchristie", "password123") with Client(dispatch=MockDispatch()) as client: response = client.get(url, auth=auth) assert response.status_code == 200 - assert json.loads(response.text) == {'auth': 'Basic dG9tY2hyaXN0aWU6cGFzc3dvcmQxMjM='} + assert json.loads(response.text) == { + "auth": "Basic dG9tY2hyaXN0aWU6cGFzc3dvcmQxMjM=" + } def test_basic_auth_in_url(): @@ -44,29 +45,33 @@ def test_basic_auth_in_url(): response = client.get(url) assert response.status_code == 200 - assert json.loads(response.text) == {'auth': 'Basic dG9tY2hyaXN0aWU6cGFzc3dvcmQxMjM='} + assert json.loads(response.text) == { + "auth": "Basic dG9tY2hyaXN0aWU6cGFzc3dvcmQxMjM=" + } def test_basic_auth_on_session(): url = "https://example.org/" - auth = ('tomchristie', 'password123') + auth = ("tomchristie", "password123") with Client(dispatch=MockDispatch(), auth=auth) as client: response = client.get(url) assert response.status_code == 200 - assert json.loads(response.text) == {'auth': 'Basic dG9tY2hyaXN0aWU6cGFzc3dvcmQxMjM='} + assert json.loads(response.text) == { + "auth": "Basic dG9tY2hyaXN0aWU6cGFzc3dvcmQxMjM=" + } def test_custom_auth(): url = "https://example.org/" def auth(request): - request.headers['Authorization'] = 'Token 123' + request.headers["Authorization"] = "Token 123" return request with Client(dispatch=MockDispatch()) as client: response = client.get(url, auth=auth) assert response.status_code == 200 - assert json.loads(response.text) == {'auth': 'Token 123'} + assert json.loads(response.text) == {"auth": "Token 123"} diff --git a/tests/conftest.py b/tests/conftest.py index 3eff9888..1d209517 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -54,13 +54,13 @@ async def status_code(scope, receive, send): async def echo_body(scope, receive, send): - body = b'' + body = b"" more_body = True while more_body: message = await receive() - body += message.get('body', b'') - more_body = message.get('more_body', False) + body += message.get("body", b"") + more_body = message.get("more_body", False) await send( {