diff --git a/httpcore/_async/connection.py b/httpcore/_async/connection.py index 2f439cf0..8c2355c8 100644 --- a/httpcore/_async/connection.py +++ b/httpcore/_async/connection.py @@ -67,7 +67,8 @@ def __init__( async def handle_async_request(self, request: Request) -> Response: if not self.can_handle_request(request.url.origin): raise RuntimeError( - f"Attempted to send request to {request.url.origin} on connection to {self._origin}" + f"Attempted to send request to {request.url.origin}" + f" on connection to {self._origin}" ) try: diff --git a/httpcore/_async/connection_pool.py b/httpcore/_async/connection_pool.py index 018b0ba2..e993afea 100644 --- a/httpcore/_async/connection_pool.py +++ b/httpcore/_async/connection_pool.py @@ -119,9 +119,10 @@ def __init__( self._connections: List[AsyncConnectionInterface] = [] self._requests: List[AsyncPoolRequest] = [] - # We only mutate the state of the connection pool within an 'optional_thread_lock' - # context. This holds a threading lock unless we're running in async mode, - # in which case it is a no-op. + # We only mutate the state of the connection pool + # within an 'optional_thread_lock' context. + # This holds a threading lock unless we're running in + # async mode, in which case it is a no-op. self._optional_thread_lock = AsyncThreadLock() def create_connection(self, origin: Origin) -> AsyncConnectionInterface: @@ -148,9 +149,12 @@ def connections(self) -> List[AsyncConnectionInterface]: ```python >>> pool.connections [ - , - , - , + , + , + , ] ``` """ @@ -160,7 +164,7 @@ async def handle_async_request(self, request: Request) -> Response: """ Send an HTTP request, and return an HTTP response. - This is the core implementation that is called into by `.request()` or `.stream()`. + The core implementation that is called into by `.request()` or `.stream()`. """ scheme = request.url.scheme.decode() if scheme == "": diff --git a/httpcore/_async/http2.py b/httpcore/_async/http2.py index 8dc776ff..0002a76f 100644 --- a/httpcore/_async/http2.py +++ b/httpcore/_async/http2.py @@ -470,10 +470,10 @@ async def _write_outgoing_data(self, request: Request) -> None: except Exception as exc: # pragma: nocover # If we get a network error we should: # - # 1. Save the exception and just raise it immediately on any future write. - # (For example, this means that a single write timeout or disconnect will - # immediately close all pending streams. Without requiring multiple - # sequential timeouts.) + # 1. Save the exception and just raise it immediately on any + # future write. (For example, this means that a single write timeout + # or disconnect will immediately close all pending streams, + # without requiring multiple sequential timeouts.) # 2. Mark the connection as errored, so that we don't accept any other # incoming requests. self._write_exception = exc diff --git a/httpcore/_async/http_proxy.py b/httpcore/_async/http_proxy.py index 4aa7d874..f4837ee5 100644 --- a/httpcore/_async/http_proxy.py +++ b/httpcore/_async/http_proxy.py @@ -89,7 +89,8 @@ def __init__( ssl_context: An SSL context to use for verifying connections. If not specified, the default `httpcore.default_ssl_context()` will be used. - proxy_ssl_context: The same as `ssl_context`, but for a proxy server rather than a remote origin. + proxy_ssl_context: The same as `ssl_context`, but for a proxy server + rather than a remote origin. max_connections: The maximum number of concurrent HTTP connections that the pool should allow. Any attempt to send a request on a pool that would exceed this amount will block until a connection is available. diff --git a/httpcore/_backends/trio.py b/httpcore/_backends/trio.py index b1626d28..4cecef6e 100644 --- a/httpcore/_backends/trio.py +++ b/httpcore/_backends/trio.py @@ -82,7 +82,8 @@ async def start_tls( def get_extra_info(self, info: str) -> typing.Any: if info == "ssl_object" and isinstance(self._stream, trio.SSLStream): - # Type checkers cannot see `_ssl_object` attribute because trio._ssl.SSLStream uses __getattr__/__setattr__. + # Type checkers cannot see `_ssl_object` attribute + # because `trio._ssl.SSLStream` uses `__getattr__`/`__setattr__`. # Tracked at https://github.com/python-trio/trio/issues/542 return self._stream._ssl_object # type: ignore[attr-defined] if info == "client_addr": diff --git a/httpcore/_sync/connection.py b/httpcore/_sync/connection.py index c3890f34..399bba9c 100644 --- a/httpcore/_sync/connection.py +++ b/httpcore/_sync/connection.py @@ -67,7 +67,8 @@ def __init__( def handle_request(self, request: Request) -> Response: if not self.can_handle_request(request.url.origin): raise RuntimeError( - f"Attempted to send request to {request.url.origin} on connection to {self._origin}" + f"Attempted to send request to {request.url.origin}" + f" on connection to {self._origin}" ) try: diff --git a/httpcore/_sync/connection_pool.py b/httpcore/_sync/connection_pool.py index 8dcf348c..5894261a 100644 --- a/httpcore/_sync/connection_pool.py +++ b/httpcore/_sync/connection_pool.py @@ -119,9 +119,10 @@ def __init__( self._connections: List[ConnectionInterface] = [] self._requests: List[PoolRequest] = [] - # We only mutate the state of the connection pool within an 'optional_thread_lock' - # context. This holds a threading lock unless we're running in async mode, - # in which case it is a no-op. + # We only mutate the state of the connection pool + # within an 'optional_thread_lock' context. + # This holds a threading lock unless we're running in + # async mode, in which case it is a no-op. self._optional_thread_lock = ThreadLock() def create_connection(self, origin: Origin) -> ConnectionInterface: @@ -148,9 +149,12 @@ def connections(self) -> List[ConnectionInterface]: ```python >>> pool.connections [ - , - , - , + , + , + , ] ``` """ @@ -160,7 +164,7 @@ def handle_request(self, request: Request) -> Response: """ Send an HTTP request, and return an HTTP response. - This is the core implementation that is called into by `.request()` or `.stream()`. + The core implementation that is called into by `.request()` or `.stream()`. """ scheme = request.url.scheme.decode() if scheme == "": diff --git a/httpcore/_sync/http2.py b/httpcore/_sync/http2.py index d141d459..abd026e1 100644 --- a/httpcore/_sync/http2.py +++ b/httpcore/_sync/http2.py @@ -470,10 +470,10 @@ def _write_outgoing_data(self, request: Request) -> None: except Exception as exc: # pragma: nocover # If we get a network error we should: # - # 1. Save the exception and just raise it immediately on any future write. - # (For example, this means that a single write timeout or disconnect will - # immediately close all pending streams. Without requiring multiple - # sequential timeouts.) + # 1. Save the exception and just raise it immediately on any + # future write. (For example, this means that a single write timeout + # or disconnect will immediately close all pending streams, + # without requiring multiple sequential timeouts.) # 2. Mark the connection as errored, so that we don't accept any other # incoming requests. self._write_exception = exc diff --git a/httpcore/_sync/http_proxy.py b/httpcore/_sync/http_proxy.py index 6acac9a7..912d6099 100644 --- a/httpcore/_sync/http_proxy.py +++ b/httpcore/_sync/http_proxy.py @@ -89,7 +89,8 @@ def __init__( ssl_context: An SSL context to use for verifying connections. If not specified, the default `httpcore.default_ssl_context()` will be used. - proxy_ssl_context: The same as `ssl_context`, but for a proxy server rather than a remote origin. + proxy_ssl_context: The same as `ssl_context`, but for a proxy server + rather than a remote origin. max_connections: The maximum number of concurrent HTTP connections that the pool should allow. Any attempt to send a request on a pool that would exceed this amount will block until a connection is available. diff --git a/pyproject.toml b/pyproject.toml index a35ad6b3..9bf77ea4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -60,7 +60,7 @@ include = [ "/httpcore", "/CHANGELOG.md", "/README.md", - "/tests" + "/tests", ] [tool.hatch.metadata.hooks.fancy-pypi-readme] @@ -96,26 +96,27 @@ filterwarnings = ["error"] [tool.coverage.run] omit = [ - "venv/*", - "httpcore/_sync/*" + "venv/*", + "httpcore/_sync/*", +] +include = [ + "httpcore/*", + "tests/*", ] -include = ["httpcore/*", "tests/*"] [tool.ruff] exclude = [ "httpcore/_sync", "tests/_sync", ] -line-length = 88 + +[tool.ruff.lint] select = [ "E", "F", "W", - "I" + "I", ] -[tool.ruff.pycodestyle] -max-line-length = 120 - -[tool.ruff.isort] +[tool.ruff.lint.isort] combine-as-imports = true diff --git a/tests/_async/test_connection.py b/tests/_async/test_connection.py index b6ee0c7e..b5093c28 100644 --- a/tests/_async/test_connection.py +++ b/tests/_async/test_connection.py @@ -42,9 +42,9 @@ async def test_http_connection(): assert repr(conn) == "" async with conn.stream("GET", "https://example.com/") as response: - assert ( - repr(conn) - == "" + assert repr(conn) == ( + "" ) await response.aread() @@ -55,9 +55,9 @@ async def test_http_connection(): assert not conn.is_closed() assert conn.is_available() assert not conn.has_expired() - assert ( - repr(conn) - == "" + assert repr(conn) == ( + "" ) diff --git a/tests/_async/test_connection_pool.py b/tests/_async/test_connection_pool.py index 2fc27204..192cd769 100644 --- a/tests/_async/test_connection_pool.py +++ b/tests/_async/test_connection_pool.py @@ -36,11 +36,12 @@ async def test_connection_pool_with_keepalive(): async with pool.stream("GET", "https://example.com/") as response: info = [repr(c) for c in pool.connections] assert info == [ - "" + "" ] - assert ( - repr(pool) - == "" + assert repr(pool) == ( + "" ) await response.aread() @@ -48,22 +49,25 @@ async def test_connection_pool_with_keepalive(): assert response.content == b"Hello, world!" info = [repr(c) for c in pool.connections] assert info == [ - "" + "" ] - assert ( - repr(pool) - == "" + assert repr(pool) == ( + "" ) - # Sending a second request to the same origin will reuse the existing IDLE connection. + # Sending a second request to the same origin will + # reuse the existing IDLE connection. async with pool.stream("GET", "https://example.com/") as response: info = [repr(c) for c in pool.connections] assert info == [ - "" + "" ] - assert ( - repr(pool) - == "" + assert repr(pool) == ( + "" ) await response.aread() @@ -71,23 +75,27 @@ async def test_connection_pool_with_keepalive(): assert response.content == b"Hello, world!" info = [repr(c) for c in pool.connections] assert info == [ - "" + "" ] - assert ( - repr(pool) - == "" + assert repr(pool) == ( + "" ) - # Sending a request to a different origin will not reuse the existing IDLE connection. + # Sending a request to a different origin will not + # reuse the existing IDLE connection. async with pool.stream("GET", "http://example.com/") as response: info = [repr(c) for c in pool.connections] assert info == [ - "", - "", + "", + "", ] - assert ( - repr(pool) - == "" + assert repr(pool) == ( + "" ) await response.aread() @@ -95,12 +103,14 @@ async def test_connection_pool_with_keepalive(): assert response.content == b"Hello, world!" info = [repr(c) for c in pool.connections] assert info == [ - "", - "", + "", + "", ] - assert ( - repr(pool) - == "" + assert repr(pool) == ( + "" ) @@ -127,7 +137,8 @@ async def test_connection_pool_with_close(): ) as response: info = [repr(c) for c in pool.connections] assert info == [ - "" + "" ] await response.aread() @@ -185,17 +196,20 @@ async def test_connection_pool_with_http2(): info = [repr(c) for c in pool.connections] assert info == [ - "" + "" ] - # Sending a second request to the same origin will reuse the existing IDLE connection. + # Sending a second request to the same origin will + # reuse the existing IDLE connection. response = await pool.request("GET", "https://example.com/") assert response.status == 200 assert response.content == b"Hello, world!" info = [repr(c) for c in pool.connections] assert info == [ - "" + "" ] @@ -239,7 +253,8 @@ async def test_connection_pool_with_http2_goaway(): info = [repr(c) for c in pool.connections] assert info == [ - "" + "" ] # Sending a second request to the same origin will require a new connection. @@ -250,7 +265,8 @@ async def test_connection_pool_with_http2_goaway(): info = [repr(c) for c in pool.connections] assert info == [ - "", + "", ] @@ -321,7 +337,8 @@ async def test_debug_request(caplog): ( "httpcore.connection", logging.DEBUG, - "connect_tcp.started host='example.com' port=80 local_address=None timeout=None socket_options=None", + "connect_tcp.started host='example.com' port=80 local_address=None" + " timeout=None socket_options=None", ), ( "httpcore.connection", @@ -349,7 +366,8 @@ async def test_debug_request(caplog): "httpcore.http11", logging.DEBUG, "receive_response_headers.complete return_value=" - "(b'HTTP/1.1', 200, b'OK', [(b'Content-Type', b'plain/text'), (b'Content-Length', b'13')])", + "(b'HTTP/1.1', 200, b'OK', [(b'Content-Type', b'plain/text')," + " (b'Content-Length', b'13')])", ), ( "httpcore.http11", @@ -470,7 +488,8 @@ async def test_connection_pool_with_immediate_expiry(): async with pool.stream("GET", "https://example.com/") as response: info = [repr(c) for c in pool.connections] assert info == [ - "" + "" ] await response.aread() @@ -503,7 +522,8 @@ async def test_connection_pool_with_no_keepalive_connections_allowed(): async with pool.stream("GET", "https://example.com/") as response: info = [repr(c) for c in pool.connections] assert info == [ - "" + "" ] await response.aread() @@ -550,11 +570,16 @@ async def fetch(pool, domain, info_list): # Each connection was to a different host, and only sent a single # request on that connection. assert item[0] in [ - "", - "", - "", - "", - "", + "", + "", + "", + "", + "", ] @@ -594,9 +619,9 @@ async def fetch(pool, domain, info_list): # single connection was established at any one time. assert len(item) == 1 # Only a single request was sent on each connection. - assert ( - item[0] - == "" + assert item[0] == ( + "" ) @@ -637,16 +662,21 @@ async def fetch(pool, domain, info_list): assert len(item) == 1 # The connection sent multiple requests. assert item[0] in [ - "", - "", - "", - "", - "", + "", + "", + "", + "", + "", ] - assert ( - repr(pool) - == "" + assert repr(pool) == ( + "" ) diff --git a/tests/_async/test_http11.py b/tests/_async/test_http11.py index 489d68b4..db34011a 100644 --- a/tests/_async/test_http11.py +++ b/tests/_async/test_http11.py @@ -26,9 +26,9 @@ async def test_http11_connection(): assert not conn.is_closed() assert conn.is_available() assert not conn.has_expired() - assert ( - repr(conn) - == "" + assert repr(conn) == ( + "" ) @@ -56,9 +56,9 @@ async def test_http11_connection_unread_response(): assert conn.is_closed() assert not conn.is_available() assert not conn.has_expired() - assert ( - repr(conn) - == "" + assert repr(conn) == ( + "" ) @@ -78,9 +78,9 @@ async def test_http11_connection_with_remote_protocol_error(): assert conn.is_closed() assert not conn.is_available() assert not conn.has_expired() - assert ( - repr(conn) - == "" + assert repr(conn) == ( + "" ) @@ -107,9 +107,9 @@ async def test_http11_connection_with_incomplete_response(): assert conn.is_closed() assert not conn.is_available() assert not conn.has_expired() - assert ( - repr(conn) - == "" + assert repr(conn) == ( + "" ) @@ -139,9 +139,9 @@ async def test_http11_connection_with_local_protocol_error(): assert conn.is_closed() assert not conn.is_available() assert not conn.has_expired() - assert ( - repr(conn) - == "" + assert repr(conn) == ( + "" ) diff --git a/tests/_async/test_http2.py b/tests/_async/test_http2.py index b4ec6648..fe1c1516 100644 --- a/tests/_async/test_http2.py +++ b/tests/_async/test_http2.py @@ -40,9 +40,9 @@ async def test_http2_connection(): assert ( conn.info() == "'https://example.com:443', HTTP/2, IDLE, Request Count: 1" ) - assert ( - repr(conn) - == "" + assert repr(conn) == ( + "" ) diff --git a/tests/_async/test_http_proxy.py b/tests/_async/test_http_proxy.py index b35fc289..5a4475d2 100644 --- a/tests/_async/test_http_proxy.py +++ b/tests/_async/test_http_proxy.py @@ -40,7 +40,8 @@ async def test_proxy_forwarding(): async with proxy.stream("GET", "http://example.com/") as response: info = [repr(c) for c in proxy.connections] assert info == [ - "" + "" ] await response.aread() @@ -48,13 +49,15 @@ async def test_proxy_forwarding(): assert response.content == b"Hello, world!" info = [repr(c) for c in proxy.connections] assert info == [ - "" + "" ] assert proxy.connections[0].is_idle() assert proxy.connections[0].is_available() assert not proxy.connections[0].is_closed() - # A connection on a forwarding proxy can only handle HTTP requests to the same origin. + # A connection on a forwarding proxy can only + # handle HTTP requests to the same origin. assert proxy.connections[0].can_handle_request( Origin(b"http", b"example.com", 80) ) @@ -95,7 +98,8 @@ async def test_proxy_tunneling(): async with proxy.stream("GET", "https://example.com/") as response: info = [repr(c) for c in proxy.connections] assert info == [ - "" + "" ] await response.aread() @@ -103,13 +107,15 @@ async def test_proxy_tunneling(): assert response.content == b"Hello, world!" info = [repr(c) for c in proxy.connections] assert info == [ - "" + "" ] assert proxy.connections[0].is_idle() assert proxy.connections[0].is_available() assert not proxy.connections[0].is_closed() - # A connection on a tunneled proxy can only handle HTTPS requests to the same origin. + # A connection on a tunneled proxy can only + # handle HTTPS requests to the same origin. assert not proxy.connections[0].can_handle_request( Origin(b"http", b"example.com", 80) ) @@ -187,7 +193,8 @@ async def test_proxy_tunneling_http2(): async with proxy.stream("GET", "https://example.com/") as response: info = [repr(c) for c in proxy.connections] assert info == [ - "" + "" ] await response.aread() @@ -195,13 +202,15 @@ async def test_proxy_tunneling_http2(): assert response.content == b"Hello, world!" info = [repr(c) for c in proxy.connections] assert info == [ - "" + "" ] assert proxy.connections[0].is_idle() assert proxy.connections[0].is_available() assert not proxy.connections[0].is_closed() - # A connection on a tunneled proxy can only handle HTTPS requests to the same origin. + # A connection on a tunneled proxy can only + # handle HTTPS requests to the same origin. assert not proxy.connections[0].can_handle_request( Origin(b"http", b"example.com", 80) ) diff --git a/tests/_async/test_socks_proxy.py b/tests/_async/test_socks_proxy.py index 3f5dd1cc..c70c8c61 100644 --- a/tests/_async/test_socks_proxy.py +++ b/tests/_async/test_socks_proxy.py @@ -32,7 +32,8 @@ async def test_socks5_request(): async with proxy.stream("GET", "https://example.com/") as response: info = [repr(c) for c in proxy.connections] assert info == [ - "" + "" ] await response.aread() @@ -40,13 +41,15 @@ async def test_socks5_request(): assert response.content == b"Hello, world!" info = [repr(c) for c in proxy.connections] assert info == [ - "" + "" ] assert proxy.connections[0].is_idle() assert proxy.connections[0].is_available() assert not proxy.connections[0].is_closed() - # A connection on a tunneled proxy can only handle HTTPS requests to the same origin. + # A connection on a tunneled proxy can only + # handle HTTPS requests to the same origin. assert not proxy.connections[0].can_handle_request( httpcore.Origin(b"http", b"example.com", 80) ) @@ -93,7 +96,8 @@ async def test_authenticated_socks5_request(): async with proxy.stream("GET", "https://example.com/") as response: info = [repr(c) for c in proxy.connections] assert info == [ - "" + "" ] await response.aread() @@ -101,7 +105,8 @@ async def test_authenticated_socks5_request(): assert response.content == b"Hello, world!" info = [repr(c) for c in proxy.connections] assert info == [ - "" + "" ] assert proxy.connections[0].is_idle() assert proxy.connections[0].is_available() @@ -157,9 +162,9 @@ async def test_socks5_request_failed_to_provide_auth(): # Sending a request, which the proxy rejects with pytest.raises(httpcore.ProxyError) as exc_info: await proxy.request("GET", "https://example.com/") - assert ( - str(exc_info.value) - == "Requested NO AUTHENTICATION REQUIRED from proxy server, but got USERNAME/PASSWORD." + assert str(exc_info.value) == ( + "Requested NO AUTHENTICATION REQUIRED from proxy server," + " but got USERNAME/PASSWORD." ) assert not proxy.connections diff --git a/tests/_sync/test_connection.py b/tests/_sync/test_connection.py index 37c82e02..dca76cbf 100644 --- a/tests/_sync/test_connection.py +++ b/tests/_sync/test_connection.py @@ -42,9 +42,9 @@ def test_http_connection(): assert repr(conn) == "" with conn.stream("GET", "https://example.com/") as response: - assert ( - repr(conn) - == "" + assert repr(conn) == ( + "" ) response.read() @@ -55,9 +55,9 @@ def test_http_connection(): assert not conn.is_closed() assert conn.is_available() assert not conn.has_expired() - assert ( - repr(conn) - == "" + assert repr(conn) == ( + "" ) diff --git a/tests/_sync/test_connection_pool.py b/tests/_sync/test_connection_pool.py index ee303e5c..45a8133b 100644 --- a/tests/_sync/test_connection_pool.py +++ b/tests/_sync/test_connection_pool.py @@ -36,11 +36,12 @@ def test_connection_pool_with_keepalive(): with pool.stream("GET", "https://example.com/") as response: info = [repr(c) for c in pool.connections] assert info == [ - "" + "" ] - assert ( - repr(pool) - == "" + assert repr(pool) == ( + "" ) response.read() @@ -48,22 +49,25 @@ def test_connection_pool_with_keepalive(): assert response.content == b"Hello, world!" info = [repr(c) for c in pool.connections] assert info == [ - "" + "" ] - assert ( - repr(pool) - == "" + assert repr(pool) == ( + "" ) - # Sending a second request to the same origin will reuse the existing IDLE connection. + # Sending a second request to the same origin will + # reuse the existing IDLE connection. with pool.stream("GET", "https://example.com/") as response: info = [repr(c) for c in pool.connections] assert info == [ - "" + "" ] - assert ( - repr(pool) - == "" + assert repr(pool) == ( + "" ) response.read() @@ -71,23 +75,27 @@ def test_connection_pool_with_keepalive(): assert response.content == b"Hello, world!" info = [repr(c) for c in pool.connections] assert info == [ - "" + "" ] - assert ( - repr(pool) - == "" + assert repr(pool) == ( + "" ) - # Sending a request to a different origin will not reuse the existing IDLE connection. + # Sending a request to a different origin will not + # reuse the existing IDLE connection. with pool.stream("GET", "http://example.com/") as response: info = [repr(c) for c in pool.connections] assert info == [ - "", - "", + "", + "", ] - assert ( - repr(pool) - == "" + assert repr(pool) == ( + "" ) response.read() @@ -95,12 +103,14 @@ def test_connection_pool_with_keepalive(): assert response.content == b"Hello, world!" info = [repr(c) for c in pool.connections] assert info == [ - "", - "", + "", + "", ] - assert ( - repr(pool) - == "" + assert repr(pool) == ( + "" ) @@ -127,7 +137,8 @@ def test_connection_pool_with_close(): ) as response: info = [repr(c) for c in pool.connections] assert info == [ - "" + "" ] response.read() @@ -185,17 +196,20 @@ def test_connection_pool_with_http2(): info = [repr(c) for c in pool.connections] assert info == [ - "" + "" ] - # Sending a second request to the same origin will reuse the existing IDLE connection. + # Sending a second request to the same origin will + # reuse the existing IDLE connection. response = pool.request("GET", "https://example.com/") assert response.status == 200 assert response.content == b"Hello, world!" info = [repr(c) for c in pool.connections] assert info == [ - "" + "" ] @@ -239,7 +253,8 @@ def test_connection_pool_with_http2_goaway(): info = [repr(c) for c in pool.connections] assert info == [ - "" + "" ] # Sending a second request to the same origin will require a new connection. @@ -250,7 +265,8 @@ def test_connection_pool_with_http2_goaway(): info = [repr(c) for c in pool.connections] assert info == [ - "", + "", ] @@ -321,7 +337,8 @@ def test_debug_request(caplog): ( "httpcore.connection", logging.DEBUG, - "connect_tcp.started host='example.com' port=80 local_address=None timeout=None socket_options=None", + "connect_tcp.started host='example.com' port=80 local_address=None" + " timeout=None socket_options=None", ), ( "httpcore.connection", @@ -349,7 +366,8 @@ def test_debug_request(caplog): "httpcore.http11", logging.DEBUG, "receive_response_headers.complete return_value=" - "(b'HTTP/1.1', 200, b'OK', [(b'Content-Type', b'plain/text'), (b'Content-Length', b'13')])", + "(b'HTTP/1.1', 200, b'OK', [(b'Content-Type', b'plain/text')," + " (b'Content-Length', b'13')])", ), ( "httpcore.http11", @@ -470,7 +488,8 @@ def test_connection_pool_with_immediate_expiry(): with pool.stream("GET", "https://example.com/") as response: info = [repr(c) for c in pool.connections] assert info == [ - "" + "" ] response.read() @@ -503,7 +522,8 @@ def test_connection_pool_with_no_keepalive_connections_allowed(): with pool.stream("GET", "https://example.com/") as response: info = [repr(c) for c in pool.connections] assert info == [ - "" + "" ] response.read() @@ -550,11 +570,16 @@ def fetch(pool, domain, info_list): # Each connection was to a different host, and only sent a single # request on that connection. assert item[0] in [ - "", - "", - "", - "", - "", + "", + "", + "", + "", + "", ] @@ -594,9 +619,9 @@ def fetch(pool, domain, info_list): # single connection was established at any one time. assert len(item) == 1 # Only a single request was sent on each connection. - assert ( - item[0] - == "" + assert item[0] == ( + "" ) @@ -637,16 +662,21 @@ def fetch(pool, domain, info_list): assert len(item) == 1 # The connection sent multiple requests. assert item[0] in [ - "", - "", - "", - "", - "", + "", + "", + "", + "", + "", ] - assert ( - repr(pool) - == "" + assert repr(pool) == ( + "" ) diff --git a/tests/_sync/test_http11.py b/tests/_sync/test_http11.py index dcd80e84..67b4748c 100644 --- a/tests/_sync/test_http11.py +++ b/tests/_sync/test_http11.py @@ -26,9 +26,9 @@ def test_http11_connection(): assert not conn.is_closed() assert conn.is_available() assert not conn.has_expired() - assert ( - repr(conn) - == "" + assert repr(conn) == ( + "" ) @@ -56,9 +56,9 @@ def test_http11_connection_unread_response(): assert conn.is_closed() assert not conn.is_available() assert not conn.has_expired() - assert ( - repr(conn) - == "" + assert repr(conn) == ( + "" ) @@ -78,9 +78,9 @@ def test_http11_connection_with_remote_protocol_error(): assert conn.is_closed() assert not conn.is_available() assert not conn.has_expired() - assert ( - repr(conn) - == "" + assert repr(conn) == ( + "" ) @@ -107,9 +107,9 @@ def test_http11_connection_with_incomplete_response(): assert conn.is_closed() assert not conn.is_available() assert not conn.has_expired() - assert ( - repr(conn) - == "" + assert repr(conn) == ( + "" ) @@ -139,9 +139,9 @@ def test_http11_connection_with_local_protocol_error(): assert conn.is_closed() assert not conn.is_available() assert not conn.has_expired() - assert ( - repr(conn) - == "" + assert repr(conn) == ( + "" ) diff --git a/tests/_sync/test_http2.py b/tests/_sync/test_http2.py index 695359bd..c7e5ef65 100644 --- a/tests/_sync/test_http2.py +++ b/tests/_sync/test_http2.py @@ -40,9 +40,9 @@ def test_http2_connection(): assert ( conn.info() == "'https://example.com:443', HTTP/2, IDLE, Request Count: 1" ) - assert ( - repr(conn) - == "" + assert repr(conn) == ( + "" ) diff --git a/tests/_sync/test_http_proxy.py b/tests/_sync/test_http_proxy.py index 2d66578e..8ccd9938 100644 --- a/tests/_sync/test_http_proxy.py +++ b/tests/_sync/test_http_proxy.py @@ -40,7 +40,8 @@ def test_proxy_forwarding(): with proxy.stream("GET", "http://example.com/") as response: info = [repr(c) for c in proxy.connections] assert info == [ - "" + "" ] response.read() @@ -48,13 +49,15 @@ def test_proxy_forwarding(): assert response.content == b"Hello, world!" info = [repr(c) for c in proxy.connections] assert info == [ - "" + "" ] assert proxy.connections[0].is_idle() assert proxy.connections[0].is_available() assert not proxy.connections[0].is_closed() - # A connection on a forwarding proxy can only handle HTTP requests to the same origin. + # A connection on a forwarding proxy can only + # handle HTTP requests to the same origin. assert proxy.connections[0].can_handle_request( Origin(b"http", b"example.com", 80) ) @@ -95,7 +98,8 @@ def test_proxy_tunneling(): with proxy.stream("GET", "https://example.com/") as response: info = [repr(c) for c in proxy.connections] assert info == [ - "" + "" ] response.read() @@ -103,13 +107,15 @@ def test_proxy_tunneling(): assert response.content == b"Hello, world!" info = [repr(c) for c in proxy.connections] assert info == [ - "" + "" ] assert proxy.connections[0].is_idle() assert proxy.connections[0].is_available() assert not proxy.connections[0].is_closed() - # A connection on a tunneled proxy can only handle HTTPS requests to the same origin. + # A connection on a tunneled proxy can only + # handle HTTPS requests to the same origin. assert not proxy.connections[0].can_handle_request( Origin(b"http", b"example.com", 80) ) @@ -187,7 +193,8 @@ def test_proxy_tunneling_http2(): with proxy.stream("GET", "https://example.com/") as response: info = [repr(c) for c in proxy.connections] assert info == [ - "" + "" ] response.read() @@ -195,13 +202,15 @@ def test_proxy_tunneling_http2(): assert response.content == b"Hello, world!" info = [repr(c) for c in proxy.connections] assert info == [ - "" + "" ] assert proxy.connections[0].is_idle() assert proxy.connections[0].is_available() assert not proxy.connections[0].is_closed() - # A connection on a tunneled proxy can only handle HTTPS requests to the same origin. + # A connection on a tunneled proxy can only + # handle HTTPS requests to the same origin. assert not proxy.connections[0].can_handle_request( Origin(b"http", b"example.com", 80) ) diff --git a/tests/_sync/test_socks_proxy.py b/tests/_sync/test_socks_proxy.py index 2d39bb97..c61c9037 100644 --- a/tests/_sync/test_socks_proxy.py +++ b/tests/_sync/test_socks_proxy.py @@ -32,7 +32,8 @@ def test_socks5_request(): with proxy.stream("GET", "https://example.com/") as response: info = [repr(c) for c in proxy.connections] assert info == [ - "" + "" ] response.read() @@ -40,13 +41,15 @@ def test_socks5_request(): assert response.content == b"Hello, world!" info = [repr(c) for c in proxy.connections] assert info == [ - "" + "" ] assert proxy.connections[0].is_idle() assert proxy.connections[0].is_available() assert not proxy.connections[0].is_closed() - # A connection on a tunneled proxy can only handle HTTPS requests to the same origin. + # A connection on a tunneled proxy can only + # handle HTTPS requests to the same origin. assert not proxy.connections[0].can_handle_request( httpcore.Origin(b"http", b"example.com", 80) ) @@ -93,7 +96,8 @@ def test_authenticated_socks5_request(): with proxy.stream("GET", "https://example.com/") as response: info = [repr(c) for c in proxy.connections] assert info == [ - "" + "" ] response.read() @@ -101,7 +105,8 @@ def test_authenticated_socks5_request(): assert response.content == b"Hello, world!" info = [repr(c) for c in proxy.connections] assert info == [ - "" + "" ] assert proxy.connections[0].is_idle() assert proxy.connections[0].is_available() @@ -157,9 +162,9 @@ def test_socks5_request_failed_to_provide_auth(): # Sending a request, which the proxy rejects with pytest.raises(httpcore.ProxyError) as exc_info: proxy.request("GET", "https://example.com/") - assert ( - str(exc_info.value) - == "Requested NO AUTHENTICATION REQUIRED from proxy server, but got USERNAME/PASSWORD." + assert str(exc_info.value) == ( + "Requested NO AUTHENTICATION REQUIRED from proxy server," + " but got USERNAME/PASSWORD." ) assert not proxy.connections diff --git a/unasync.py b/unasync.py index 5a5627d7..b8dee7bc 100755 --- a/unasync.py +++ b/unasync.py @@ -5,7 +5,10 @@ from pprint import pprint SUBS = [ - ('from .._backends.auto import AutoBackend', 'from .._backends.sync import SyncBackend'), + ( + 'from .._backends.auto import AutoBackend', + 'from .._backends.sync import SyncBackend', + ), ('import trio as concurrency', 'from tests import concurrency'), ('AsyncIterator', 'Iterator'), ('Async([A-Z][A-Za-z0-9_]*)', r'\2'), @@ -87,8 +90,8 @@ def main(): print("These patterns were not used:") pprint(unused_subs) - exit(1) - + exit(1) + if __name__ == '__main__': main()