]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Linting 1/head
authorTom Christie <tom@tomchristie.com>
Sat, 6 Apr 2019 12:20:47 +0000 (13:20 +0100)
committerTom Christie <tom@tomchristie.com>
Sat, 6 Apr 2019 12:20:47 +0000 (13:20 +0100)
httpcore/connections.py
tests/conftest.py
tests/test_api.py

index db27b03c153da7cac17bfe2728841a3d5bee00fa..312fc46cd946f27e9120c8291d69278548d95365 100644 (file)
@@ -40,7 +40,7 @@ class Connection:
         except asyncio.TimeoutError:
             raise ConnectTimeout()
 
-    async def send(self, request: Request, stream: bool=False) -> Response:
+    async def send(self, request: Request, stream: bool = False) -> Response:
         method = request.method.encode()
         target = request.url.target
         host_header = (b"host", request.url.netloc.encode("ascii"))
@@ -77,7 +77,8 @@ class Connection:
         headers = event.headers
 
         if stream:
-            return Response(status_code=status_code, headers=headers, body=self.body_iter())
+            body_iter = self.body_iter()
+            return Response(status_code=status_code, headers=headers, body=body_iter)
 
         #  Get the response body.
         body = b""
@@ -90,7 +91,7 @@ class Connection:
 
         return Response(status_code=status_code, headers=headers, body=body)
 
-    async def body_iter(self) -> typing.Iterable[bytes]:
+    async def body_iter(self) -> typing.AsyncIterator[bytes]:
         event = await self._receive_event()
         while isinstance(event, h11.Data):
             yield event.data
index 08e36702a58bad848561cf3118bf1c2824357e8c..234cf43bb8f22670996a5bb95ee6260cccc84131 100644 (file)
@@ -1,5 +1,4 @@
 import asyncio
-import json
 
 import pytest
 from uvicorn.config import Config
@@ -7,18 +6,15 @@ from uvicorn.main import Server
 
 
 async def app(scope, receive, send):
-    assert scope['type'] == 'http'
-    await send({
-        'type': 'http.response.start',
-        'status': 200,
-        'headers': [
-            [b'content-type', b'text/plain'],
-        ]
-    })
-    await send({
-        'type': 'http.response.body',
-        'body': b'Hello, world!',
-    })
+    assert scope["type"] == "http"
+    await send(
+        {
+            "type": "http.response.start",
+            "status": 200,
+            "headers": [[b"content-type", b"text/plain"]],
+        }
+    )
+    await send({"type": "http.response.body", "body": b"Hello, world!"})
 
 
 @pytest.fixture
index c24e7373316e7b24d7a6d56e9828c38690035de5..6b80587dbc4f475f27175ba9175093c06b257431 100644 (file)
@@ -1,30 +1,33 @@
 import pytest
+
 import httpcore
 
 
 @pytest.mark.asyncio
 async def test_get(server):
     async with httpcore.ConnectionPool() as http:
-        response = await http.request('GET', "http://127.0.0.1:8000/")
+        response = await http.request("GET", "http://127.0.0.1:8000/")
     assert response.status_code == 200
-    assert response.body == b'Hello, world!'
+    assert response.body == b"Hello, world!"
 
 
 @pytest.mark.asyncio
 async def test_post(server):
     async with httpcore.ConnectionPool() as http:
-        response = await http.request('POST', "http://127.0.0.1:8000/", body=b"Hello, world!")
+        response = await http.request(
+            "POST", "http://127.0.0.1:8000/", body=b"Hello, world!"
+        )
     assert response.status_code == 200
 
 
 @pytest.mark.asyncio
 async def test_stream_response(server):
     async with httpcore.ConnectionPool() as http:
-        response = await http.request('GET', "http://127.0.0.1:8000/", stream=True)
+        response = await http.request("GET", "http://127.0.0.1:8000/", stream=True)
     assert response.status_code == 200
-    assert not hasattr(response, 'body')
+    assert not hasattr(response, "body")
     body = await response.read()
-    assert body == b'Hello, world!'
+    assert body == b"Hello, world!"
 
 
 @pytest.mark.asyncio
@@ -34,5 +37,7 @@ async def test_stream_request(server):
         yield b"world!"
 
     async with httpcore.ConnectionPool() as http:
-        response = await http.request('POST', "http://127.0.0.1:8000/", body=hello_world())
+        response = await http.request(
+            "POST", "http://127.0.0.1:8000/", body=hello_world()
+        )
     assert response.status_code == 200