From: Tom Christie Date: Fri, 27 Sep 2024 12:00:30 +0000 (+0100) Subject: Merge branch 'master' into async-dependencies-optional X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e58ae69e95d901af76f63f150af89e34b99a9ab;p=thirdparty%2Fhttpx.git Merge branch 'master' into async-dependencies-optional --- 4e58ae69e95d901af76f63f150af89e34b99a9ab diff --cc README.md index f3238242,d5d21487..15d52d45 --- a/README.md +++ b/README.md @@@ -134,13 -132,13 +134,14 @@@ The HTTPX project relies on these excel As well as these optional installs: -* `h2` - HTTP/2 support. *(Optional, with `httpx[http2]`)* -* `socksio` - SOCKS proxy support. *(Optional, with `httpx[socks]`)* -* `rich` - Rich terminal support. *(Optional, with `httpx[cli]`)* -* `click` - Command line client support. *(Optional, with `httpx[cli]`)* -* `brotli` or `brotlicffi` - Decoding for "brotli" compressed responses. *(Optional, with `httpx[brotli]`)* +* `anyio` - Async support for `asyncio`. *(Optional, with `httpx['asyncio']`)* +* `trio` - Async support for `trio`. *(Optional, with `httpx['trio']`)* +* `h2` - HTTP/2 support. *(Optional, with `httpx['http2']`)* +* `socksio` - SOCKS proxy support. *(Optional, with `httpx['socks']`)* +* `rich` - Rich terminal support. *(Optional, with `httpx['cli']`)* +* `click` - Command line client support. *(Optional, with `httpx['cli']`)* +* `brotli` or `brotlicffi` - Decoding for "brotli" compressed responses. *(Optional, with `httpx['brotli']`)* + * `zstandard` - Decoding for "zstd" compressed responses. *(Optional, with `httpx[zstd]`)* A huge amount of credit is due to `requests` for the API layout that much of this work follows, as well as to `urllib3` for plenty of design diff --cc httpx/_transports/asgi.py index fd9ffdce,8578d4ae..17ad2b0a --- a/httpx/_transports/asgi.py +++ b/httpx/_transports/asgi.py @@@ -1,5 -1,9 +1,7 @@@ + from __future__ import annotations + import typing -import sniffio - from .._models import Request, Response from .._types import AsyncByteStream from .base import AsyncBaseTransport @@@ -12,19 -16,19 +14,21 @@@ if typing.TYPE_CHECKING: # pragma: no Event = typing.Union[asyncio.Event, trio.Event] - _Message = typing.Dict[str, typing.Any] + _Message = typing.MutableMapping[str, typing.Any] _Receive = typing.Callable[[], typing.Awaitable[_Message]] _Send = typing.Callable[ - [typing.Dict[str, typing.Any]], typing.Coroutine[None, None, None] + [typing.MutableMapping[str, typing.Any]], typing.Awaitable[None] ] _ASGIApp = typing.Callable[ - [typing.Dict[str, typing.Any], _Receive, _Send], typing.Coroutine[None, None, None] + [typing.MutableMapping[str, typing.Any], _Receive, _Send], typing.Awaitable[None] ] + __all__ = ["ASGITransport"] + -def create_event() -> Event: +def create_event() -> "Event": + import sniffio + if sniffio.current_async_library() == "trio": import trio diff --cc httpx/_transports/default.py index 9e9ce90e,33db416d..3ebf2102 --- a/httpx/_transports/default.py +++ b/httpx/_transports/default.py @@@ -266,20 -271,12 +271,20 @@@ class AsyncHTTPTransport(AsyncBaseTrans http2: bool = False, limits: Limits = DEFAULT_LIMITS, trust_env: bool = True, - proxy: typing.Optional[ProxyTypes] = None, - uds: typing.Optional[str] = None, - local_address: typing.Optional[str] = None, + proxy: ProxyTypes | None = None, + uds: str | None = None, + local_address: str | None = None, retries: int = 0, - socket_options: typing.Optional[typing.Iterable[SOCKET_OPTION]] = None, + socket_options: typing.Iterable[SOCKET_OPTION] | None = None, ) -> None: + try: + import sniffio # noqa: F401 + except ImportError: # pragma: nocover + raise RuntimeError( + "Using httpx in async mode, but neither " + "httpx['asyncio'] or asyncio['trio'] is installed." + ) + ssl_context = create_ssl_context(verify=verify, cert=cert, trust_env=trust_env) proxy = Proxy(url=proxy) if isinstance(proxy, (str, URL)) else proxy diff --cc pyproject.toml index 271694d2,c4c18805..484989a1 --- a/pyproject.toml +++ b/pyproject.toml @@@ -45,17 -47,14 +45,20 @@@ cli = "rich>=10,<14", ] http2 = [ - "h2>=3,<5", + "httpcore[http2]", ] socks = [ - "socksio==1.*", + "httpcore[socks]", +] +asyncio = [ + "httpcore[asyncio]" +] +trio = [ + "httpcore[trio]" ] + zstd = [ + "zstandard>=0.18.0", + ] [project.scripts] httpx = "httpx:main" diff --cc requirements.txt index 31f05044,5aab0376..bb2ddd20 --- a/requirements.txt +++ b/requirements.txt @@@ -2,27 -2,28 +2,27 @@@ # On the other hand, we're not pinning package dependencies, because our tests # needs to pass with the latest version of the packages. # Reference: https://github.com/encode/httpx/pull/1721#discussion_r661241588 - -e .[asyncio,trio,brotli,cli,http2,socks] --e .[brotli,cli,http2,socks,zstd] ++-e .[asyncio,trio,brotli,cli,http2,socks,zstd] # Optional charset auto-detection # Used in our test cases chardet==5.2.0 # Documentation - mkdocs==1.5.3 + mkdocs==1.6.1 mkautodoc==0.2.0 - mkdocs-material==9.5.3 + mkdocs-material==9.5.34 # Packaging - build==1.0.3 - twine==4.0.2 + build==1.2.1 + twine==5.1.1 # Tests & Linting - coverage[toml]==7.4.0 - cryptography==41.0.7 - mypy==1.8.0 - pytest==7.4.4 - ruff==0.1.9 - trio==0.22.2 + coverage[toml]==7.6.1 + cryptography==43.0.1 + mypy==1.11.2 + pytest==8.3.2 + ruff==0.6.3 + trio==0.26.2 -trio-typing==0.10.0 trustme==1.1.0 - uvicorn==0.24.0.post1 + uvicorn==0.30.6