]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Drop deprecated API (#1057)
authorTom Christie <tom@tomchristie.com>
Wed, 15 Jul 2020 11:19:56 +0000 (12:19 +0100)
committerGitHub <noreply@github.com>
Wed, 15 Jul 2020 11:19:56 +0000 (12:19 +0100)
* Drop ASGIDispatch, WSGIDispatch, which has been replaced by ASGITransport, WSGITransport.
* Drop dispatch=... on client, which has been replaced by transport=...
* Drop soft_limit, hard_limit, which have been replaced by max_keepalive and max_connections.
* Drop Response.stream and Response.raw, which have been replaced by aiter_bytes and aiter_raw.
* Drop internal usage of as_network_error in favour of map_exceptions.

httpx/__init__.py
httpx/_client.py
httpx/_config.py
httpx/_models.py
httpx/_transports/asgi.py
httpx/_transports/urllib3.py
httpx/_transports/wsgi.py
httpx/_utils.py
tests/client/test_async_client.py
tests/client/test_client.py
tests/test_exceptions.py

index 155ea5c57802ba44fd6152fe6603fff861acbb79..a45dd549dd58a028fc0f635631955f012766306f 100644 (file)
@@ -32,9 +32,9 @@ from ._exceptions import (
 )
 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 @@ __all__ = [
     "request",
     "stream",
     "codes",
-    "ASGIDispatch",
     "ASGITransport",
     "AsyncClient",
     "Auth",
@@ -96,6 +95,5 @@ __all__ = [
     "Request",
     "Response",
     "DigestAuth",
-    "WSGIDispatch",
     "WSGITransport",
 ]
index fd9c1e54d9f4a609ab057e7cea89d80a482e3137..32b51950b2a481306c9be13ee9c87344f5c71ab6 100644 (file)
@@ -48,7 +48,6 @@ from ._utils import (
     get_environment_proxies,
     get_logger,
     should_not_be_proxied,
-    warn_deprecated,
 )
 
 logger = get_logger(__name__)
@@ -433,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
@@ -456,7 +454,6 @@ class Client(BaseClient):
         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,
     ):
@@ -473,14 +470,6 @@ class Client(BaseClient):
 
         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,
@@ -981,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
@@ -1004,7 +992,6 @@ class AsyncClient(BaseClient):
         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 +1006,6 @@ class AsyncClient(BaseClient):
             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(
index b50acb2321ce5cbb877f3257b44a8d4c9ea71411..43f712b8b76cbe020d17b167a40804f681b30c22 100644 (file)
@@ -8,7 +8,7 @@ import certifi
 
 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 (
index 0437de1c4133062064b9b72ba075a33b5711f7f4..bf5f6d1cdd40011badeca36b7328ce5acab848b5 100644 (file)
@@ -51,7 +51,6 @@ from ._utils import (
     obfuscate_sensitive_headers,
     parse_header_links,
     str_query_param,
-    warn_deprecated,
 )
 
 
@@ -874,22 +873,6 @@ class Response:
     def __repr__(self) -> str:
         return f"<Response [{self.status_code} {self.reason_phrase}]>"
 
-    @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.
index dc44850d10c341820a5e3bab55cb9797e652ff6d..465f49cef1165db5c31e74ef7c164ab6595c126d 100644 (file)
@@ -4,7 +4,6 @@ import httpcore
 import sniffio
 
 from .._content_streams import ByteStream
-from .._utils import warn_deprecated
 
 if TYPE_CHECKING:  # pragma: no cover
     import asyncio
@@ -159,20 +158,3 @@ class ASGITransport(httpcore.AsyncHTTPTransport):
         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,
-        )
index fe8a89ba85daacdbb95e8eccb3451bab1bffeae7..0bbb2b3eb5a69e81f7ed71000c66078c6cfcf093 100644 (file)
@@ -5,8 +5,8 @@ import httpcore
 
 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 @@ class URLLib3Transport(httpcore.SyncHTTPTransport):
                 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 @@ class URLLib3Transport(httpcore.SyncHTTPTransport):
             )
 
         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
 
index 717270d40dd54dc891fdeec74ae8e58697d049f5..3203caf4717c083fa4c616c95f5e4e9d1241875d 100644 (file)
@@ -5,7 +5,6 @@ import typing
 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 @@ class WSGITransport(httpcore.SyncHTTPTransport):
         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,
-        )
index e38a662a2f7448a9d955fa0d81275c3096b84cf0..8c01eb16c4c4fe30d27d6766f47e2415e4f6f609 100644 (file)
@@ -1,6 +1,5 @@
 import codecs
 import collections
-import contextlib
 import logging
 import mimetypes
 import netrc
@@ -15,7 +14,6 @@ from time import perf_counter
 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 @@ class ElapsedTimer:
         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)
index 6818b4a444b3b1c76ac1c0c5419237fca9edced9..7cb537a0f385a281812bd093a081d3749de616cb 100644 (file)
@@ -1,10 +1,8 @@
 from datetime import timedelta
 
-import httpcore
 import pytest
 
 import httpx
-from httpx import ASGIDispatch
 
 
 @pytest.mark.usefixtures("async_environment")
@@ -157,31 +155,3 @@ async def test_100_continue(server):
 
     assert response.status_code == 200
     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
-
-    with pytest.warns(DeprecationWarning) as record:
-        ASGIDispatch(app)
-
-    assert len(record) == 1
-    assert (
-        record[0].message.args[0]
-        == "ASGIDispatch is deprecated, please use ASGITransport"
-    )
index 1426fc216c4b395be6de41a92ae25145a9cd3d90..ec08e36ee8963f2b474e107032ce60de9890d412 100644 (file)
@@ -1,10 +1,8 @@
 from datetime import timedelta
 
-import httpcore
 import pytest
 
 import httpx
-from httpx import WSGIDispatch
 
 
 def test_get(server):
@@ -165,31 +163,3 @@ def test_merge_url():
 
     assert url.scheme == "https"
     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
-
-    with pytest.warns(DeprecationWarning) as record:
-        WSGIDispatch(app)
-
-    assert len(record) == 1
-    assert (
-        record[0].message.args[0]
-        == "WSGIDispatch is deprecated, please use WSGITransport"
-    )
index 34a1752596b6082a29b5434a8f43c3ce35e03099..d1f6f7a4a807ab455d40e4425a266cad9834ff39 100644 (file)
@@ -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}")