]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Drop unused interface on ConnectionStore (#70)
authorTom Christie <tom@tomchristie.com>
Thu, 16 May 2019 09:56:05 +0000 (10:56 +0100)
committerGitHub <noreply@github.com>
Thu, 16 May 2019 09:56:05 +0000 (10:56 +0100)
httpcore/dispatch/connection_pool.py
httpcore/models.py
tests/client/test_auth.py
tests/conftest.py

index e0fb642e35dd0566b11b0da2dd47004a9183aa30..ba92acd057c1f6077f51590243ef19c52249858b 100644 (file)
@@ -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)
 
index 663b64007533cab3ef717f3798b60671bb8f6994..ea26fa4c9c641b480562f5ef8e1b6a4a3b5c95a6 100644 (file)
@@ -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:
index e044acd8b62fcb432404f2c877207f8fb2a1ca27..6e4db0c54d39e942d0e9a4b8bd4c4d405b13c6a1 100644 (file)
@@ -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"}
index 3eff9888f25a164cecb114f383f2c3a0a148d961..1d20951725e65af31fc03554f2182770ea897bd7 100644 (file)
@@ -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(
         {