From 14475f72971022885fc1d7077aaa1edfcd9e64c3 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Wed, 15 Jul 2020 10:04:46 +0100 Subject: [PATCH 1/4] Drop deprecated API --- httpx/_client.py | 18 ------------------ httpx/_models.py | 17 ----------------- 2 files changed, 35 deletions(-) diff --git a/httpx/_client.py b/httpx/_client.py index fd9c1e54d9..99f467502a 100644 --- a/httpx/_client.py +++ b/httpx/_client.py @@ -48,7 +48,6 @@ get_environment_proxies, get_logger, should_not_be_proxied, - warn_deprecated, ) logger = get_logger(__name__) @@ -473,14 +472,6 @@ def __init__( proxy_map = self.get_proxy_map(proxies, trust_env) - if dispatch is not None: - warn_deprecated( - "The dispatch argument is deprecated since v0.13 and will be " - "removed in a future release, please use 'transport'" - ) - if transport is None: - transport = dispatch - self.transport = self.init_transport( verify=verify, cert=cert, @@ -1004,7 +995,6 @@ def __init__( max_redirects: int = DEFAULT_MAX_REDIRECTS, base_url: URLTypes = None, transport: httpcore.AsyncHTTPTransport = None, - dispatch: httpcore.AsyncHTTPTransport = None, app: typing.Callable = None, trust_env: bool = True, ): @@ -1019,14 +1009,6 @@ def __init__( trust_env=trust_env, ) - if dispatch is not None: - warn_deprecated( - "The dispatch argument is deprecated since v0.13 and will be " - "removed in a future release, please use 'transport'", - ) - if transport is None: - transport = dispatch - proxy_map = self.get_proxy_map(proxies, trust_env) self.transport = self.init_transport( diff --git a/httpx/_models.py b/httpx/_models.py index 0437de1c41..bf5f6d1cdd 100644 --- a/httpx/_models.py +++ b/httpx/_models.py @@ -51,7 +51,6 @@ obfuscate_sensitive_headers, parse_header_links, str_query_param, - warn_deprecated, ) @@ -874,22 +873,6 @@ def links(self) -> typing.Dict[typing.Optional[str], typing.Dict[str, str]]: def __repr__(self) -> str: return f"" - @property - def stream(self): # type: ignore - warn_deprecated( # pragma: nocover - "Response.stream() is due to be deprecated. " - "Use Response.aiter_bytes() instead.", - ) - return self.aiter_bytes # pragma: nocover - - @property - def raw(self): # type: ignore - warn_deprecated( # pragma: nocover - "Response.raw() is due to be deprecated. " - "Use Response.aiter_raw() instead.", - ) - return self.aiter_raw # pragma: nocover - def read(self) -> bytes: """ Read and return the response content. From e031b930de36ccac273b390b67852916a10716c5 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Wed, 15 Jul 2020 11:14:39 +0100 Subject: [PATCH 2/4] Drop deprecated API --- httpx/_client.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/httpx/_client.py b/httpx/_client.py index 99f467502a..32b51950b2 100644 --- a/httpx/_client.py +++ b/httpx/_client.py @@ -432,7 +432,6 @@ class Client(BaseClient): request URLs. * **transport** - *(optional)* A transport class to use for sending requests over the network. - * **dispatch** - *(optional)* A deprecated alias for transport. * **app** - *(optional)* An WSGI application to send requests to, rather than sending actual network requests. * **trust_env** - *(optional)* Enables or disables usage of environment @@ -455,7 +454,6 @@ def __init__( max_redirects: int = DEFAULT_MAX_REDIRECTS, base_url: URLTypes = None, transport: httpcore.SyncHTTPTransport = None, - dispatch: httpcore.SyncHTTPTransport = None, app: typing.Callable = None, trust_env: bool = True, ): @@ -972,7 +970,6 @@ class AsyncClient(BaseClient): request URLs. * **transport** - *(optional)* A transport class to use for sending requests over the network. - * **dispatch** - *(optional)* A deprecated alias for transport. * **app** - *(optional)* An ASGI application to send requests to, rather than sending actual network requests. * **trust_env** - *(optional)* Enables or disables usage of environment From 2b2c3e8503c3cc905d6ce69f2b62b68d164cac01 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Wed, 15 Jul 2020 11:16:54 +0100 Subject: [PATCH 3/4] Drop WSGIDispatch, ASGIDispatch --- httpx/__init__.py | 6 ++---- httpx/_transports/asgi.py | 18 ------------------ httpx/_transports/wsgi.py | 18 ------------------ tests/client/test_async_client.py | 14 -------------- tests/client/test_client.py | 14 -------------- 5 files changed, 2 insertions(+), 68 deletions(-) diff --git a/httpx/__init__.py b/httpx/__init__.py index 155ea5c578..a45dd549dd 100644 --- a/httpx/__init__.py +++ b/httpx/__init__.py @@ -32,9 +32,9 @@ ) from ._models import URL, Cookies, Headers, QueryParams, Request, Response from ._status_codes import StatusCode, codes -from ._transports.asgi import ASGIDispatch, ASGITransport +from ._transports.asgi import ASGITransport from ._transports.urllib3 import URLLib3ProxyTransport, URLLib3Transport -from ._transports.wsgi import WSGIDispatch, WSGITransport +from ._transports.wsgi import WSGITransport __all__ = [ "__description__", @@ -51,7 +51,6 @@ "request", "stream", "codes", - "ASGIDispatch", "ASGITransport", "AsyncClient", "Auth", @@ -96,6 +95,5 @@ "Request", "Response", "DigestAuth", - "WSGIDispatch", "WSGITransport", ] diff --git a/httpx/_transports/asgi.py b/httpx/_transports/asgi.py index dc44850d10..465f49cef1 100644 --- a/httpx/_transports/asgi.py +++ b/httpx/_transports/asgi.py @@ -4,7 +4,6 @@ import sniffio from .._content_streams import ByteStream -from .._utils import warn_deprecated if TYPE_CHECKING: # pragma: no cover import asyncio @@ -159,20 +158,3 @@ async def send(message: dict) -> None: stream = ByteStream(b"".join(body_parts)) return (b"HTTP/1.1", status_code, b"", response_headers, stream) - - -class ASGIDispatch(ASGITransport): - def __init__( - self, - app: Callable, - raise_app_exceptions: bool = True, - root_path: str = "", - client: Tuple[str, int] = ("127.0.0.1", 123), - ) -> None: - warn_deprecated("ASGIDispatch is deprecated, please use ASGITransport") - super().__init__( - app=app, - raise_app_exceptions=raise_app_exceptions, - root_path=root_path, - client=client, - ) diff --git a/httpx/_transports/wsgi.py b/httpx/_transports/wsgi.py index 717270d40d..3203caf471 100644 --- a/httpx/_transports/wsgi.py +++ b/httpx/_transports/wsgi.py @@ -5,7 +5,6 @@ import httpcore from .._content_streams import ByteStream, IteratorStream -from .._utils import warn_deprecated def _skip_leading_empty_chunks(body: typing.Iterable) -> typing.Iterable: @@ -132,20 +131,3 @@ def start_response( stream = IteratorStream(chunk for chunk in result) return (b"HTTP/1.1", status_code, b"", headers, stream) - - -class WSGIDispatch(WSGITransport): - def __init__( - self, - app: typing.Callable, - raise_app_exceptions: bool = True, - script_name: str = "", - remote_addr: str = "127.0.0.1", - ) -> None: - warn_deprecated("WSGIDispatch is deprecated, please use WSGITransport") - super().__init__( - app=app, - raise_app_exceptions=raise_app_exceptions, - script_name=script_name, - remote_addr=remote_addr, - ) diff --git a/tests/client/test_async_client.py b/tests/client/test_async_client.py index 6818b4a444..13af427e4f 100644 --- a/tests/client/test_async_client.py +++ b/tests/client/test_async_client.py @@ -159,20 +159,6 @@ async def test_100_continue(server): assert response.content == data -def test_dispatch_deprecated(): - dispatch = httpcore.AsyncHTTPTransport() - - with pytest.warns(DeprecationWarning) as record: - client = httpx.AsyncClient(dispatch=dispatch) - - assert client.transport is dispatch - assert len(record) == 1 - assert record[0].message.args[0] == ( - "The dispatch argument is deprecated since v0.13 and will be " - "removed in a future release, please use 'transport'" - ) - - def test_asgi_dispatch_deprecated(): async def app(scope, receive, send): pass diff --git a/tests/client/test_client.py b/tests/client/test_client.py index 1426fc216c..2c3ef64fc8 100644 --- a/tests/client/test_client.py +++ b/tests/client/test_client.py @@ -167,20 +167,6 @@ def test_merge_url(): assert url.is_ssl -def test_dispatch_deprecated(): - dispatch = httpcore.SyncHTTPTransport() - - with pytest.warns(DeprecationWarning) as record: - client = httpx.Client(dispatch=dispatch) - - assert client.transport is dispatch - assert len(record) == 1 - assert record[0].message.args[0] == ( - "The dispatch argument is deprecated since v0.13 and will be " - "removed in a future release, please use 'transport'" - ) - - def test_wsgi_dispatch_deprecated(): def app(start_response, environ): pass From 49e8c3326aafc2bb2408cf7cafade4f888fee20d Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Wed, 15 Jul 2020 11:29:26 +0100 Subject: [PATCH 4/4] Drop deprecated API --- httpx/_config.py | 17 ++--------------- httpx/_transports/urllib3.py | 12 +++++++++--- httpx/_utils.py | 15 +-------------- tests/client/test_async_client.py | 16 ---------------- tests/client/test_client.py | 16 ---------------- tests/test_exceptions.py | 4 ++-- 6 files changed, 14 insertions(+), 66 deletions(-) diff --git a/httpx/_config.py b/httpx/_config.py index b50acb2321..43f712b8b7 100644 --- a/httpx/_config.py +++ b/httpx/_config.py @@ -8,7 +8,7 @@ from ._models import URL, Headers from ._types import CertTypes, HeaderTypes, TimeoutTypes, URLTypes, VerifyTypes -from ._utils import get_ca_bundle_from_env, get_logger, warn_deprecated +from ._utils import get_ca_bundle_from_env, get_logger DEFAULT_CIPHERS = ":".join( [ @@ -295,23 +295,10 @@ class PoolLimits: """ def __init__( - self, - *, - max_keepalive: int = None, - max_connections: int = None, - soft_limit: int = None, - hard_limit: int = None, + self, *, max_keepalive: int = None, max_connections: int = None, ): self.max_keepalive = max_keepalive self.max_connections = max_connections - if soft_limit is not None: # pragma: nocover - self.max_keepalive = soft_limit - warn_deprecated("'soft_limit' is deprecated. Use 'max_keepalive' instead.",) - if hard_limit is not None: # pragma: nocover - self.max_connections = hard_limit - warn_deprecated( - "'hard_limit' is deprecated. Use 'max_connections' instead.", - ) def __eq__(self, other: typing.Any) -> bool: return ( diff --git a/httpx/_transports/urllib3.py b/httpx/_transports/urllib3.py index fe8a89ba85..0bbb2b3eb5 100644 --- a/httpx/_transports/urllib3.py +++ b/httpx/_transports/urllib3.py @@ -5,8 +5,8 @@ from .._config import Proxy, SSLConfig from .._content_streams import ByteStream, IteratorStream +from .._exceptions import NetworkError, map_exceptions from .._types import CertTypes, VerifyTypes -from .._utils import as_network_error try: import urllib3 @@ -84,7 +84,13 @@ def request( path.decode("ascii"), ) - with as_network_error(MaxRetryError, SSLError, socket.error): + with map_exceptions( + { + MaxRetryError: NetworkError, + SSLError: NetworkError, + socket.error: NetworkError, + } + ): conn = self.pool.urlopen( method=method.decode(), url=url_str, @@ -102,7 +108,7 @@ def request( ) def response_bytes() -> Iterator[bytes]: - with as_network_error(socket.error): + with map_exceptions({socket.error: NetworkError}): for chunk in conn.stream(4096, decode_content=False): yield chunk diff --git a/httpx/_utils.py b/httpx/_utils.py index e38a662a2f..8c01eb16c4 100644 --- a/httpx/_utils.py +++ b/httpx/_utils.py @@ -1,6 +1,5 @@ import codecs import collections -import contextlib import logging import mimetypes import netrc @@ -15,7 +14,6 @@ from types import TracebackType from urllib.request import getproxies -from ._exceptions import NetworkError from ._types import PrimitiveData if typing.TYPE_CHECKING: # pragma: no cover @@ -396,16 +394,5 @@ def elapsed(self) -> timedelta: return timedelta(seconds=self.end - self.start) -@contextlib.contextmanager -def as_network_error(*exception_classes: type) -> typing.Iterator[None]: - try: - yield - except BaseException as exc: - for cls in exception_classes: - if isinstance(exc, cls): - raise NetworkError(exc) from exc - raise - - -def warn_deprecated(message: str) -> None: +def warn_deprecated(message: str) -> None: # pragma: nocover warnings.warn(message, DeprecationWarning, stacklevel=2) diff --git a/tests/client/test_async_client.py b/tests/client/test_async_client.py index 13af427e4f..7cb537a0f3 100644 --- a/tests/client/test_async_client.py +++ b/tests/client/test_async_client.py @@ -1,10 +1,8 @@ from datetime import timedelta -import httpcore import pytest import httpx -from httpx import ASGIDispatch @pytest.mark.usefixtures("async_environment") @@ -157,17 +155,3 @@ async def test_100_continue(server): assert response.status_code == 200 assert response.content == data - - -def test_asgi_dispatch_deprecated(): - async def app(scope, receive, send): - pass - - with pytest.warns(DeprecationWarning) as record: - ASGIDispatch(app) - - assert len(record) == 1 - assert ( - record[0].message.args[0] - == "ASGIDispatch is deprecated, please use ASGITransport" - ) diff --git a/tests/client/test_client.py b/tests/client/test_client.py index 2c3ef64fc8..ec08e36ee8 100644 --- a/tests/client/test_client.py +++ b/tests/client/test_client.py @@ -1,10 +1,8 @@ from datetime import timedelta -import httpcore import pytest import httpx -from httpx import WSGIDispatch def test_get(server): @@ -165,17 +163,3 @@ def test_merge_url(): assert url.scheme == "https" assert url.is_ssl - - -def test_wsgi_dispatch_deprecated(): - def app(start_response, environ): - pass - - with pytest.warns(DeprecationWarning) as record: - WSGIDispatch(app) - - assert len(record) == 1 - assert ( - record[0].message.args[0] - == "WSGIDispatch is deprecated, please use WSGITransport" - ) diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py index 34a1752596..d1f6f7a4a8 100644 --- a/tests/test_exceptions.py +++ b/tests/test_exceptions.py @@ -20,7 +20,7 @@ def test_httpcore_all_exceptions_mapped() -> None: and value not in HTTPCORE_EXC_MAP ] - if not_mapped: + if not_mapped: # pragma: nocover pytest.fail(f"Unmapped httpcore exceptions: {not_mapped}") @@ -57,5 +57,5 @@ def test_httpx_exceptions_exposed() -> None: and not hasattr(httpx, name) ] - if not_exposed: + if not_exposed: # pragma: nocover pytest.fail(f"Unexposed HTTPX exceptions: {not_exposed}")