Skip to content
Myr

Dispatcher -> AsyncDispatcher (#725)

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

* Dispatcher -> AsyncDispatcher * Fix invalid renamings * Fix invalid renamings

authored by Tom Christie · committed by GitHub · parent 6ac49da · Browse files · 12 files+38 added−37 removed
This commit

State

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

Diff stats

12 files+38 added−37 removed

  • tests:+14 added−14 removed
  • other:+24 added−23 removed

12 files+38 added−37 removed

modified:httpx/dispatch/asgi.py+3 added-3 removed
1 unmodified line
23from ..config import TimeoutTypes4from ..content_streams import ByteStream5from ..models import Request, Response6from .base import Dispatcher6from .base import AsyncDispatcher789class ASGIDispatch(Dispatcher):9class ASGIDispatch(AsyncDispatcher):10 """11 A custom dispatcher that handles sending requests directly to an ASGI app.11 A custom AsyncDispatcher that handles sending requests directly to an ASGI app.1213 The simplest way to use this functionality is to use the `app` argument.14 This will automatically infer if 'app' is a WSGI or an ASGI application,15 and will setup an appropriate dispatch class:
111 unmodified lines
modified:httpx/dispatch/base.py+4 added-4 removed
10 unmodified lines
11 URLTypes,12)131415class Dispatcher:15class AsyncDispatcher:16 """17 Base class for dispatcher classes, that handle sending the request.17 Base class for AsyncDispatcher classes, that handle sending the request.1819 Stubs out the interface, as well as providing a `.request()` convenience20 implementation, to make it easy to use or test stand-alone dispatchers,20 implementation, to make it easy to use or test stand-alone AsyncDispatchers,21 without requiring a complete `AsyncClient` instance.22 """2324 async def request(
14 unmodified lines
3940 async def close(self) -> None:41 pass # pragma: nocover4243 async def __aenter__(self) -> "Dispatcher":43 async def __aenter__(self) -> "AsyncDispatcher":44 return self4546 async def __aexit__(47 self,
5 unmodified lines
modified:httpx/dispatch/connection_pool.py+2 added-2 removed
10 unmodified lines
11)12from ..exceptions import PoolTimeout13from ..models import Origin, Request, Response14from ..utils import get_logger15from .base import Dispatcher15from .base import AsyncDispatcher16from .connection import HTTPConnection1718CONNECTIONS_DICT = typing.Dict[Origin, typing.List[HTTPConnection]]19
64 unmodified lines
84 def __len__(self) -> int:85 return len(self.all)868788class ConnectionPool(Dispatcher):88class ConnectionPool(AsyncDispatcher):89 KEEP_ALIVE_EXPIRY = 5.09091 def __init__(92 self,
129 unmodified lines
modified:httpx/dispatch/connection.py+2 added-2 removed
5 unmodified lines
6from ..backends.base import ConcurrencyBackend, lookup_backend7from ..config import SSLConfig, Timeout8from ..models import URL, Origin, Request, Response9from ..utils import get_logger10from .base import Dispatcher10from .base import AsyncDispatcher11from .http2 import HTTP2Connection12from .http11 import HTTP11Connection1314# Callback signature: async def callback(conn: HTTPConnection) -> None
2 unmodified lines
1718logger = get_logger(__name__)192021class HTTPConnection(Dispatcher):21class HTTPConnection(AsyncDispatcher):22 def __init__(23 self,24 origin: typing.Union[str, Origin],25 ssl: SSLConfig = None,
124 unmodified lines
modified:httpx/client.py+9 added-10 removed
19 unmodified lines
20 VerifyTypes,21)22from .content_streams import ContentStream23from .dispatch.asgi import ASGIDispatch24from .dispatch.base import Dispatcher24from .dispatch.base import AsyncDispatcher25from .dispatch.connection_pool import ConnectionPool26from .dispatch.proxy_http import HTTPProxy27from .exceptions import (28 HTTPError,
90 unmodified lines
119 timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,120 pool_limits: PoolLimits = DEFAULT_POOL_LIMITS,121 max_redirects: int = DEFAULT_MAX_REDIRECTS,122 base_url: URLTypes = None,123 dispatch: Dispatcher = None,123 dispatch: AsyncDispatcher = None,124 app: typing.Callable = None,125 backend: typing.Union[str, ConcurrencyBackend] = "auto",126 trust_env: bool = True,127 uds: str = None,
32 unmodified lines
160161 if proxies is None and trust_env:162 proxies = typing.cast(ProxiesTypes, get_environment_proxies())163164 self.proxies: typing.Dict[str, Dispatcher] = _proxies_to_dispatchers(164 self.proxies: typing.Dict[str, AsyncDispatcher] = _proxies_to_dispatchers(165 proxies,166 verify=verify,167 cert=cert,168 http2=http2,
451 unmodified lines
620 logger.debug(f'HTTP Request: {request.method} {request.url} "{response_line}"')621622 return response623624 def dispatcher_for_url(self, url: URL) -> Dispatcher:624 def dispatcher_for_url(self, url: URL) -> AsyncDispatcher:625 """626 Returns the Dispatcher instance that should be used for a given URL.626 Returns the AsyncDispatcher instance that should be used for a given URL.627 This will either be the standard connection pool, or a proxy.628 """629 if self.proxies:630 is_default_port = (url.scheme == "http" and url.port == 80) or (
9 unmodified lines
640 "all",641 )642 for proxy_key in proxy_keys:643 if proxy_key and proxy_key in self.proxies:644 dispatcher = self.proxies[proxy_key]645 return dispatcher644 return self.proxies[proxy_key]645646 return self.dispatch647648 async def get(
246 unmodified lines
895 http2: bool,896 pool_limits: PoolLimits,897 backend: typing.Union[str, ConcurrencyBackend],898 trust_env: bool,900) -> typing.Dict[str, Dispatcher]:901 def _proxy_from_url(url: URLTypes) -> Dispatcher:899) -> typing.Dict[str, AsyncDispatcher]:900 def _proxy_from_url(url: URLTypes) -> AsyncDispatcher:901 nonlocal verify, cert, http2, pool_limits, backend, trust_env902 url = URL(url)903 if url.scheme in ("http", "https"):904 return HTTPProxy(
10 unmodified lines
915 if proxies is None:916 return {}917 elif isinstance(proxies, (str, URL)):918 return {"all": _proxy_from_url(proxies)}920 elif isinstance(proxies, Dispatcher):919 elif isinstance(proxies, AsyncDispatcher):920 return {"all": proxies}921 else:922 new_proxies = {}923 for key, dispatcher_or_url in proxies.items():
48 unmodified lines
modified:httpx/models.py+4 added-2 removed
50 unmodified lines
51 str_query_param,52)5354if typing.TYPE_CHECKING: # pragma: no cover55 from .dispatch.base import Dispatcher # noqa: F40155 from .dispatch.base import AsyncDispatcher # noqa: F4015657PrimitiveData = typing.Optional[typing.Union[str, int, float, bool]]5859URLTypes = typing.Union["URL", str]
13 unmodified lines
7374CookieTypes = typing.Union["Cookies", CookieJar, typing.Dict[str, str]]7576ProxiesTypes = typing.Union[77 URLTypes, "Dispatcher", typing.Dict[URLTypes, typing.Union[URLTypes, "Dispatcher"]]77 URLTypes,78 "AsyncDispatcher",79 typing.Dict[URLTypes, typing.Union[URLTypes, "AsyncDispatcher"]],80]818283class URL:
1095 unmodified lines
modified:tests/client/test_auth.py+3 added-3 removed
14 unmodified lines
15 Response,16)17from httpx.auth import Auth, AuthFlow18from httpx.config import CertTypes, TimeoutTypes, VerifyTypes19from httpx.dispatch.base import Dispatcher19from httpx.dispatch.base import AsyncDispatcher202122class MockDispatch(Dispatcher):22class MockDispatch(AsyncDispatcher):23 def __init__(self, auth_header: str = "", status_code: int = 200) -> None:24 self.auth_header = auth_header25 self.status_code = status_code26
10 unmodified lines
37 self.status_code, headers=headers, content=body, request=request38 )394041class MockDigestAuthDispatch(Dispatcher):41class MockDigestAuthDispatch(AsyncDispatcher):42 def __init__(43 self,44 algorithm: str = "SHA-256",45 send_response_after_attempt: int = 1,
420 unmodified lines
modified:tests/client/test_cookies.py+2 added-2 removed
3 unmodified lines
4import pytest56from httpx import AsyncClient, Cookies, Request, Response7from httpx.config import CertTypes, TimeoutTypes, VerifyTypes8from httpx.dispatch.base import Dispatcher8from httpx.dispatch.base import AsyncDispatcher91011class MockDispatch(Dispatcher):11class MockDispatch(AsyncDispatcher):12 async def send(13 self,14 request: Request,15 verify: VerifyTypes = None,
149 unmodified lines
modified:tests/client/test_headers.py+2 added-2 removed
4 unmodified lines
5import pytest67from httpx import AsyncClient, Headers, Request, Response, __version__8from httpx.config import CertTypes, TimeoutTypes, VerifyTypes9from httpx.dispatch.base import Dispatcher9from httpx.dispatch.base import AsyncDispatcher101112class MockDispatch(Dispatcher):12class MockDispatch(AsyncDispatcher):13 async def send(14 self,15 request: Request,16 verify: VerifyTypes = None,
162 unmodified lines
modified:tests/client/test_queryparams.py+2 added-2 removed
2 unmodified lines
3import pytest45from httpx import URL, AsyncClient, QueryParams, Request, Response6from httpx.config import CertTypes, TimeoutTypes, VerifyTypes7from httpx.dispatch.base import Dispatcher7from httpx.dispatch.base import AsyncDispatcher8910class MockDispatch(Dispatcher):10class MockDispatch(AsyncDispatcher):11 async def send(12 self,13 request: Request,14 verify: VerifyTypes = None,
37 unmodified lines
modified:tests/client/test_redirects.py+3 added-3 removed
13 unmodified lines
14 TooManyRedirects,15 codes,16)17from httpx.config import CertTypes, TimeoutTypes, VerifyTypes18from httpx.dispatch.base import Dispatcher18from httpx.dispatch.base import AsyncDispatcher192021class MockDispatch(Dispatcher):21class MockDispatch(AsyncDispatcher):22 async def send(23 self,24 request: Request,25 verify: VerifyTypes = None,
278 unmodified lines
304 response = await client.get(url)305 assert response.url == URL("https://www.example.org/cross_subdomain")306307308class MockCookieDispatch(Dispatcher):308class MockCookieDispatch(AsyncDispatcher):309 async def send(310 self,311 request: Request,312 verify: VerifyTypes = None,
62 unmodified lines
modified:tests/test_multipart.py+2 added-2 removed
7 unmodified lines
89import httpx10from httpx.config import CertTypes, TimeoutTypes, VerifyTypes11from httpx.content_streams import encode12from httpx.dispatch.base import Dispatcher12from httpx.dispatch.base import AsyncDispatcher13from httpx.utils import format_form_param141516class MockDispatch(Dispatcher):16class MockDispatch(AsyncDispatcher):17 async def send(18 self,19 request: httpx.Request,20 verify: VerifyTypes = None,
181 unmodified lines