Skip to content
Myr

Drop deprecated API (#1057)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* 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.

authored by Tom Christie · committed by GitHub · parent df24a0f · Browse files · 11 files+16 added−172 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

11 files+16 added−172 removed

  • tests:+2 added−62 removed
  • other:+14 added−110 removed

11 files+16 added−172 removed

modified:httpx/_transports/asgi.py-18 removed
2 unmodified lines
3import httpcore4import sniffio56from .._content_streams import ByteStream7from .._utils import warn_deprecated78if TYPE_CHECKING: # pragma: no cover9 import asyncio10
146 unmodified lines
157158 stream = ByteStream(b"".join(body_parts))159160 return (b"HTTP/1.1", status_code, b"", response_headers, stream)162163164class ASGIDispatch(ASGITransport):165 def __init__(166 self,167 app: Callable,168 raise_app_exceptions: bool = True,169 root_path: str = "",170 client: Tuple[str, int] = ("127.0.0.1", 123),171 ) -> None:172 warn_deprecated("ASGIDispatch is deprecated, please use ASGITransport")173 super().__init__(174 app=app,175 raise_app_exceptions=raise_app_exceptions,176 root_path=root_path,177 client=client,178 )
modified:httpx/_transports/urllib3.py+9 added-3 removed
3 unmodified lines
4import httpcore56from .._config import Proxy, SSLConfig7from .._content_streams import ByteStream, IteratorStream8from .._exceptions import NetworkError, map_exceptions9from .._types import CertTypes, VerifyTypes9from .._utils import as_network_error1011try:12 import urllib313 from urllib3.exceptions import MaxRetryError, SSLError
69 unmodified lines
83 port,84 path.decode("ascii"),85 )8687 with as_network_error(MaxRetryError, SSLError, socket.error):87 with map_exceptions(88 {89 MaxRetryError: NetworkError,90 SSLError: NetworkError,91 socket.error: NetworkError,92 }93 ):94 conn = self.pool.urlopen(95 method=method.decode(),96 url=url_str,97 headers={
9 unmodified lines
107 pool_timeout=timeout.get("pool"),108 )109110 def response_bytes() -> Iterator[bytes]:105 with as_network_error(socket.error):111 with map_exceptions({socket.error: NetworkError}):112 for chunk in conn.stream(4096, decode_content=False):113 yield chunk114115 status_code = conn.status
39 unmodified lines
modified:httpx/_transports/wsgi.py-18 removed
3 unmodified lines
45import httpcore67from .._content_streams import ByteStream, IteratorStream8from .._utils import warn_deprecated8910def _skip_leading_empty_chunks(body: typing.Iterable) -> typing.Iterable:11 body = iter(body)
118 unmodified lines
130 ]131 stream = IteratorStream(chunk for chunk in result)132133 return (b"HTTP/1.1", status_code, b"", headers, stream)135136137class WSGIDispatch(WSGITransport):138 def __init__(139 self,140 app: typing.Callable,141 raise_app_exceptions: bool = True,142 script_name: str = "",143 remote_addr: str = "127.0.0.1",144 ) -> None:145 warn_deprecated("WSGIDispatch is deprecated, please use WSGITransport")146 super().__init__(147 app=app,148 raise_app_exceptions=raise_app_exceptions,149 script_name=script_name,150 remote_addr=remote_addr,151 )
modified:httpx/__init__.py+2 added-4 removed
30 unmodified lines
31 WriteTimeout,32)33from ._models import URL, Cookies, Headers, QueryParams, Request, Response34from ._status_codes import StatusCode, codes35from ._transports.asgi import ASGIDispatch, ASGITransport35from ._transports.asgi import ASGITransport36from ._transports.urllib3 import URLLib3ProxyTransport, URLLib3Transport37from ._transports.wsgi import WSGIDispatch, WSGITransport37from ._transports.wsgi import WSGITransport3839__all__ = [40 "__description__",41 "__title__",
8 unmodified lines
50 "put",51 "request",52 "stream",53 "codes",54 "ASGIDispatch",54 "ASGITransport",55 "AsyncClient",56 "Auth",57 "BasicAuth",
36 unmodified lines
94 "QueryParams",95 "Request",96 "Response",97 "DigestAuth",99 "WSGIDispatch",98 "WSGITransport",99]
modified:httpx/_client.py-21 removed
46 unmodified lines
47 NetRCInfo,48 get_environment_proxies,49 get_logger,50 should_not_be_proxied,51 warn_deprecated,51)5253logger = get_logger(__name__)54
376 unmodified lines
431 * **base_url** - *(optional)* A URL to use as the base when building432 request URLs.433 * **transport** - *(optional)* A transport class to use for sending requests434 over the network.436 * **dispatch** - *(optional)* A deprecated alias for transport.435 * **app** - *(optional)* An WSGI application to send requests to,436 rather than sending actual network requests.437 * **trust_env** - *(optional)* Enables or disables usage of environment438 variables for configuration.
14 unmodified lines
453 pool_limits: PoolLimits = DEFAULT_POOL_LIMITS,454 max_redirects: int = DEFAULT_MAX_REDIRECTS,455 base_url: URLTypes = None,456 transport: httpcore.SyncHTTPTransport = None,459 dispatch: httpcore.SyncHTTPTransport = None,457 app: typing.Callable = None,458 trust_env: bool = True,459 ):460 super().__init__(
8 unmodified lines
469 )470471 proxy_map = self.get_proxy_map(proxies, trust_env)472476 if dispatch is not None:477 warn_deprecated(478 "The dispatch argument is deprecated since v0.13 and will be "479 "removed in a future release, please use 'transport'"480 )481 if transport is None:482 transport = dispatch483473 self.transport = self.init_transport(474 verify=verify,475 cert=cert,476 http2=http2,
492 unmodified lines
969 * **base_url** - *(optional)* A URL to use as the base when building970 request URLs.971 * **transport** - *(optional)* A transport class to use for sending requests972 over the network.984 * **dispatch** - *(optional)* A deprecated alias for transport.973 * **app** - *(optional)* An ASGI application to send requests to,974 rather than sending actual network requests.975 * **trust_env** - *(optional)* Enables or disables usage of environment976 variables for configuration.
14 unmodified lines
991 pool_limits: PoolLimits = DEFAULT_POOL_LIMITS,992 max_redirects: int = DEFAULT_MAX_REDIRECTS,993 base_url: URLTypes = None,994 transport: httpcore.AsyncHTTPTransport = None,1007 dispatch: httpcore.AsyncHTTPTransport = None,995 app: typing.Callable = None,996 trust_env: bool = True,997 ):998 super().__init__(
6 unmodified lines
1005 base_url=base_url,1006 trust_env=trust_env,1007 )10081022 if dispatch is not None:1023 warn_deprecated(1024 "The dispatch argument is deprecated since v0.13 and will be "1025 "removed in a future release, please use 'transport'",1026 )1027 if transport is None:1028 transport = dispatch10291009 proxy_map = self.get_proxy_map(proxies, trust_env)10101011 self.transport = self.init_transport(1012 verify=verify,
517 unmodified lines
modified:httpx/_config.py+2 added-15 removed
6 unmodified lines
7import certifi89from ._models import URL, Headers10from ._types import CertTypes, HeaderTypes, TimeoutTypes, URLTypes, VerifyTypes11from ._utils import get_ca_bundle_from_env, get_logger, warn_deprecated11from ._utils import get_ca_bundle_from_env, get_logger1213DEFAULT_CIPHERS = ":".join(14 [15 "ECDHE+AESGCM",
278 unmodified lines
294 established.295 """296297 def __init__(298 self,299 *,300 max_keepalive: int = None,301 max_connections: int = None,302 soft_limit: int = None,303 hard_limit: int = None,298 self, *, max_keepalive: int = None, max_connections: int = None,299 ):300 self.max_keepalive = max_keepalive301 self.max_connections = max_connections307 if soft_limit is not None: # pragma: nocover308 self.max_keepalive = soft_limit309 warn_deprecated("'soft_limit' is deprecated. Use 'max_keepalive' instead.",)310 if hard_limit is not None: # pragma: nocover311 self.max_connections = hard_limit312 warn_deprecated(313 "'hard_limit' is deprecated. Use 'max_connections' instead.",314 )302303 def __eq__(self, other: typing.Any) -> bool:304 return (305 isinstance(other, self.__class__)
53 unmodified lines
modified:httpx/_models.py-17 removed
49 unmodified lines
50 normalize_header_value,51 obfuscate_sensitive_headers,52 parse_header_links,53 str_query_param,54 warn_deprecated,54)555657class URL:
814 unmodified lines
872873 def __repr__(self) -> str:874 return f"<Response [{self.status_code} {self.reason_phrase}]>"875877 @property878 def stream(self): # type: ignore879 warn_deprecated( # pragma: nocover880 "Response.stream() is due to be deprecated. "881 "Use Response.aiter_bytes() instead.",882 )883 return self.aiter_bytes # pragma: nocover884885 @property886 def raw(self): # type: ignore887 warn_deprecated( # pragma: nocover888 "Response.raw() is due to be deprecated. "889 "Use Response.aiter_raw() instead.",890 )891 return self.aiter_raw # pragma: nocover892876 def read(self) -> bytes:877 """878 Read and return the response content.879 """
315 unmodified lines
modified:httpx/_utils.py+1 added-14 removed
1import codecs2import collections3import contextlib3import logging4import mimetypes5import netrc6import os
6 unmodified lines
13from time import perf_counter14from types import TracebackType15from urllib.request import getproxies1618from ._exceptions import NetworkError17from ._types import PrimitiveData1819if typing.TYPE_CHECKING: # pragma: no cover20 from ._models import URL
372 unmodified lines
393 return timedelta(seconds=perf_counter() - self.start)394 return timedelta(seconds=self.end - self.start)395396399@contextlib.contextmanager400def as_network_error(*exception_classes: type) -> typing.Iterator[None]:401 try:402 yield403 except BaseException as exc:404 for cls in exception_classes:405 if isinstance(exc, cls):406 raise NetworkError(exc) from exc407 raise408409410def warn_deprecated(message: str) -> None:397def warn_deprecated(message: str) -> None: # pragma: nocover398 warnings.warn(message, DeprecationWarning, stacklevel=2)
modified:tests/client/test_async_client.py-30 removed
1from datetime import timedelta23import httpcore3import pytest45import httpx7from httpx import ASGIDispatch678@pytest.mark.usefixtures("async_environment")9async def test_get(server):
144 unmodified lines
154 )155156 assert response.status_code == 200157 assert response.content == data160161162def test_dispatch_deprecated():163 dispatch = httpcore.AsyncHTTPTransport()164165 with pytest.warns(DeprecationWarning) as record:166 client = httpx.AsyncClient(dispatch=dispatch)167168 assert client.transport is dispatch169 assert len(record) == 1170 assert record[0].message.args[0] == (171 "The dispatch argument is deprecated since v0.13 and will be "172 "removed in a future release, please use 'transport'"173 )174175176def test_asgi_dispatch_deprecated():177 async def app(scope, receive, send):178 pass179180 with pytest.warns(DeprecationWarning) as record:181 ASGIDispatch(app)182183 assert len(record) == 1184 assert (185 record[0].message.args[0]186 == "ASGIDispatch is deprecated, please use ASGITransport"187 )
modified:tests/client/test_client.py-30 removed
1from datetime import timedelta23import httpcore3import pytest45import httpx7from httpx import WSGIDispatch678def test_get(server):9 url = server.url
152 unmodified lines
162 url = client.merge_url("http://www.paypal.com")163164 assert url.scheme == "https"165 assert url.is_ssl168169170def test_dispatch_deprecated():171 dispatch = httpcore.SyncHTTPTransport()172173 with pytest.warns(DeprecationWarning) as record:174 client = httpx.Client(dispatch=dispatch)175176 assert client.transport is dispatch177 assert len(record) == 1178 assert record[0].message.args[0] == (179 "The dispatch argument is deprecated since v0.13 and will be "180 "removed in a future release, please use 'transport'"181 )182183184def test_wsgi_dispatch_deprecated():185 def app(start_response, environ):186 pass187188 with pytest.warns(DeprecationWarning) as record:189 WSGIDispatch(app)190191 assert len(record) == 1192 assert (193 record[0].message.args[0]194 == "WSGIDispatch is deprecated, please use WSGITransport"195 )
modified:tests/test_exceptions.py+2 added-2 removed
18 unmodified lines
19 and issubclass(value, Exception)20 and value not in HTTPCORE_EXC_MAP21 ]2223 if not_mapped:23 if not_mapped: # pragma: nocover24 pytest.fail(f"Unmapped httpcore exceptions: {not_mapped}")252627def test_httpcore_exception_mapping() -> None:
28 unmodified lines
56 and issubclass(value, Exception)57 and not hasattr(httpx, name)58 ]5960 if not_exposed:60 if not_exposed: # pragma: nocover61 pytest.fail(f"Unexposed HTTPX exceptions: {not_exposed}")