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
Provenance
- Commit
3f96e74- Tree
cdd86cc- Author
Tom Christie <tom@tomchristie.com>- Committer
GitHub <noreply@github.com>- Parent
df24a0f
11 files changed+16 added−172 removed
modified:httpx/_transports/asgi.py-18 removed
2 unmodified lines3 import httpcore4 import sniffio5 6 from .._content_streams import ByteStream7-from .._utils import warn_deprecated7 8 if TYPE_CHECKING: # pragma: no cover9 import asyncio10 146 unmodified lines157 158 stream = ByteStream(b"".join(body_parts))159 160 return (b"HTTP/1.1", status_code, b"", response_headers, stream)162-163-164-class 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 lines4 import httpcore5 6 from .._config import Proxy, SSLConfig7 from .._content_streams import ByteStream, IteratorStream8+from .._exceptions import NetworkError, map_exceptions9 from .._types import CertTypes, VerifyTypes9-from .._utils import as_network_error10 11 try:12 import urllib313 from urllib3.exceptions import MaxRetryError, SSLError69 unmodified lines83 port,84 path.decode("ascii"),85 )86 87- 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 lines107 pool_timeout=timeout.get("pool"),108 )109 110 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 chunk114 115 status_code = conn.status39 unmodified linesmodified:httpx/_transports/wsgi.py-18 removed
3 unmodified lines4 5 import httpcore6 7 from .._content_streams import ByteStream, IteratorStream8-from .._utils import warn_deprecated8 9 10 def _skip_leading_empty_chunks(body: typing.Iterable) -> typing.Iterable:11 body = iter(body)118 unmodified lines130 ]131 stream = IteratorStream(chunk for chunk in result)132 133 return (b"HTTP/1.1", status_code, b"", headers, stream)135-136-137-class 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 lines31 WriteTimeout,32 )33 from ._models import URL, Cookies, Headers, QueryParams, Request, Response34 from ._status_codes import StatusCode, codes35-from ._transports.asgi import ASGIDispatch, ASGITransport35+from ._transports.asgi import ASGITransport36 from ._transports.urllib3 import URLLib3ProxyTransport, URLLib3Transport37-from ._transports.wsgi import WSGIDispatch, WSGITransport37+from ._transports.wsgi import WSGITransport38 39 __all__ = [40 "__description__",41 "__title__",8 unmodified lines50 "put",51 "request",52 "stream",53 "codes",54- "ASGIDispatch",54 "ASGITransport",55 "AsyncClient",56 "Auth",57 "BasicAuth",36 unmodified lines94 "QueryParams",95 "Request",96 "Response",97 "DigestAuth",99- "WSGIDispatch",98 "WSGITransport",99 ]modified:httpx/_client.py-21 removed
46 unmodified lines47 NetRCInfo,48 get_environment_proxies,49 get_logger,50 should_not_be_proxied,51- warn_deprecated,51 )52 53 logger = get_logger(__name__)54 376 unmodified lines431 * **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 lines453 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 lines469 )470 471 proxy_map = self.get_proxy_map(proxies, trust_env)472 476- 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 = dispatch483-473 self.transport = self.init_transport(474 verify=verify,475 cert=cert,476 http2=http2,492 unmodified lines969 * **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 lines991 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 lines1005 base_url=base_url,1006 trust_env=trust_env,1007 )1008 1022- 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 = dispatch1029-1009 proxy_map = self.get_proxy_map(proxies, trust_env)1010 1011 self.transport = self.init_transport(1012 verify=verify,517 unmodified linesmodified:httpx/_config.py+2 added-15 removed
6 unmodified lines7 import certifi8 9 from ._models import URL, Headers10 from ._types import CertTypes, HeaderTypes, TimeoutTypes, URLTypes, VerifyTypes11-from ._utils import get_ca_bundle_from_env, get_logger, warn_deprecated11+from ._utils import get_ca_bundle_from_env, get_logger12 13 DEFAULT_CIPHERS = ":".join(14 [15 "ECDHE+AESGCM",278 unmodified lines294 established.295 """296 297 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- )302 303 def __eq__(self, other: typing.Any) -> bool:304 return (305 isinstance(other, self.__class__)53 unmodified linesmodified:httpx/_models.py-17 removed
49 unmodified lines50 normalize_header_value,51 obfuscate_sensitive_headers,52 parse_header_links,53 str_query_param,54- warn_deprecated,54 )55 56 57 class URL:814 unmodified lines872 873 def __repr__(self) -> str:874 return f"<Response [{self.status_code} {self.reason_phrase}]>"875 877- @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: nocover884-885- @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: nocover892-876 def read(self) -> bytes:877 """878 Read and return the response content.879 """315 unmodified linesmodified:httpx/_utils.py+1 added-14 removed
1 import codecs2 import collections3-import contextlib3 import logging4 import mimetypes5 import netrc6 import os6 unmodified lines13 from time import perf_counter14 from types import TracebackType15 from urllib.request import getproxies16 18-from ._exceptions import NetworkError17 from ._types import PrimitiveData18 19 if typing.TYPE_CHECKING: # pragma: no cover20 from ._models import URL372 unmodified lines393 return timedelta(seconds=perf_counter() - self.start)394 return timedelta(seconds=self.end - self.start)395 396 399-@contextlib.contextmanager400-def 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- raise408-409-410-def warn_deprecated(message: str) -> None:397+def warn_deprecated(message: str) -> None: # pragma: nocover398 warnings.warn(message, DeprecationWarning, stacklevel=2)modified:tests/client/test_async_client.py-30 removed
1 from datetime import timedelta2 3-import httpcore3 import pytest4 5 import httpx7-from httpx import ASGIDispatch6 7 8 @pytest.mark.usefixtures("async_environment")9 async def test_get(server):144 unmodified lines154 )155 156 assert response.status_code == 200157 assert response.content == data160-161-162-def test_dispatch_deprecated():163- dispatch = httpcore.AsyncHTTPTransport()164-165- with pytest.warns(DeprecationWarning) as record:166- client = httpx.AsyncClient(dispatch=dispatch)167-168- 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- )174-175-176-def test_asgi_dispatch_deprecated():177- async def app(scope, receive, send):178- pass179-180- with pytest.warns(DeprecationWarning) as record:181- ASGIDispatch(app)182-183- 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
1 from datetime import timedelta2 3-import httpcore3 import pytest4 5 import httpx7-from httpx import WSGIDispatch6 7 8 def test_get(server):9 url = server.url152 unmodified lines162 url = client.merge_url("http://www.paypal.com")163 164 assert url.scheme == "https"165 assert url.is_ssl168-169-170-def test_dispatch_deprecated():171- dispatch = httpcore.SyncHTTPTransport()172-173- with pytest.warns(DeprecationWarning) as record:174- client = httpx.Client(dispatch=dispatch)175-176- 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- )182-183-184-def test_wsgi_dispatch_deprecated():185- def app(start_response, environ):186- pass187-188- with pytest.warns(DeprecationWarning) as record:189- WSGIDispatch(app)190-191- 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 lines19 and issubclass(value, Exception)20 and value not in HTTPCORE_EXC_MAP21 ]22 23- if not_mapped:23+ if not_mapped: # pragma: nocover24 pytest.fail(f"Unmapped httpcore exceptions: {not_mapped}")25 26 27 def test_httpcore_exception_mapping() -> None:28 unmodified lines56 and issubclass(value, Exception)57 and not hasattr(httpx, name)58 ]59 60- if not_exposed:60+ if not_exposed: # pragma: nocover61 pytest.fail(f"Unexposed HTTPX exceptions: {not_exposed}")