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
Provenance
- Commit
e19bd9b- Tree
1991fbe- Author
Tom Christie <tom@tomchristie.com>- Committer
GitHub <noreply@github.com>- Parent
6ac49da
12 files changed+38 added−37 removed
modified:httpx/dispatch/asgi.py+3 added-3 removed
1 unmodified line2 3 from ..config import TimeoutTypes4 from ..content_streams import ByteStream5 from ..models import Request, Response6-from .base import Dispatcher6+from .base import AsyncDispatcher7 8 9-class ASGIDispatch(Dispatcher):9+class 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.12 13 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 linesmodified:httpx/dispatch/base.py+4 added-4 removed
10 unmodified lines11 URLTypes,12 )13 14 15-class Dispatcher:15+class AsyncDispatcher:16 """17- Base class for dispatcher classes, that handle sending the request.17+ Base class for AsyncDispatcher classes, that handle sending the request.18 19 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 """23 24 async def request(14 unmodified lines39 40 async def close(self) -> None:41 pass # pragma: nocover42 43- async def __aenter__(self) -> "Dispatcher":43+ async def __aenter__(self) -> "AsyncDispatcher":44 return self45 46 async def __aexit__(47 self,5 unmodified linesmodified:httpx/dispatch/connection_pool.py+2 added-2 removed
10 unmodified lines11 )12 from ..exceptions import PoolTimeout13 from ..models import Origin, Request, Response14 from ..utils import get_logger15-from .base import Dispatcher15+from .base import AsyncDispatcher16 from .connection import HTTPConnection17 18 CONNECTIONS_DICT = typing.Dict[Origin, typing.List[HTTPConnection]]19 64 unmodified lines84 def __len__(self) -> int:85 return len(self.all)86 87 88-class ConnectionPool(Dispatcher):88+class ConnectionPool(AsyncDispatcher):89 KEEP_ALIVE_EXPIRY = 5.090 91 def __init__(92 self,129 unmodified linesmodified:httpx/dispatch/connection.py+2 added-2 removed
5 unmodified lines6 from ..backends.base import ConcurrencyBackend, lookup_backend7 from ..config import SSLConfig, Timeout8 from ..models import URL, Origin, Request, Response9 from ..utils import get_logger10-from .base import Dispatcher10+from .base import AsyncDispatcher11 from .http2 import HTTP2Connection12 from .http11 import HTTP11Connection13 14 # Callback signature: async def callback(conn: HTTPConnection) -> None2 unmodified lines17 18 logger = get_logger(__name__)19 20 21-class HTTPConnection(Dispatcher):21+class HTTPConnection(AsyncDispatcher):22 def __init__(23 self,24 origin: typing.Union[str, Origin],25 ssl: SSLConfig = None,124 unmodified linesmodified:httpx/client.py+9 added-10 removed
19 unmodified lines20 VerifyTypes,21 )22 from .content_streams import ContentStream23 from .dispatch.asgi import ASGIDispatch24-from .dispatch.base import Dispatcher24+from .dispatch.base import AsyncDispatcher25 from .dispatch.connection_pool import ConnectionPool26 from .dispatch.proxy_http import HTTPProxy27 from .exceptions import (28 HTTPError,90 unmodified lines119 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 lines160 161 if proxies is None and trust_env:162 proxies = typing.cast(ProxiesTypes, get_environment_proxies())163 164- 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 lines620 logger.debug(f'HTTP Request: {request.method} {request.url} "{response_line}"')621 622 return response623 624- 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 lines640 "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]645 646 return self.dispatch647 648 async def get(246 unmodified lines895 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 lines915 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 linesmodified:httpx/models.py+4 added-2 removed
50 unmodified lines51 str_query_param,52 )53 54 if typing.TYPE_CHECKING: # pragma: no cover55- from .dispatch.base import Dispatcher # noqa: F40155+ from .dispatch.base import AsyncDispatcher # noqa: F40156 57 PrimitiveData = typing.Optional[typing.Union[str, int, float, bool]]58 59 URLTypes = typing.Union["URL", str]13 unmodified lines73 74 CookieTypes = typing.Union["Cookies", CookieJar, typing.Dict[str, str]]75 76 ProxiesTypes = 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 ]81 82 83 class URL:1095 unmodified linesmodified:tests/client/test_auth.py+3 added-3 removed
14 unmodified lines15 Response,16 )17 from httpx.auth import Auth, AuthFlow18 from httpx.config import CertTypes, TimeoutTypes, VerifyTypes19-from httpx.dispatch.base import Dispatcher19+from httpx.dispatch.base import AsyncDispatcher20 21 22-class MockDispatch(Dispatcher):22+class 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 lines37 self.status_code, headers=headers, content=body, request=request38 )39 40 41-class MockDigestAuthDispatch(Dispatcher):41+class MockDigestAuthDispatch(AsyncDispatcher):42 def __init__(43 self,44 algorithm: str = "SHA-256",45 send_response_after_attempt: int = 1,420 unmodified linesmodified:tests/client/test_cookies.py+2 added-2 removed
3 unmodified lines4 import pytest5 6 from httpx import AsyncClient, Cookies, Request, Response7 from httpx.config import CertTypes, TimeoutTypes, VerifyTypes8-from httpx.dispatch.base import Dispatcher8+from httpx.dispatch.base import AsyncDispatcher9 10 11-class MockDispatch(Dispatcher):11+class MockDispatch(AsyncDispatcher):12 async def send(13 self,14 request: Request,15 verify: VerifyTypes = None,149 unmodified linesmodified:tests/client/test_headers.py+2 added-2 removed
4 unmodified lines5 import pytest6 7 from httpx import AsyncClient, Headers, Request, Response, __version__8 from httpx.config import CertTypes, TimeoutTypes, VerifyTypes9-from httpx.dispatch.base import Dispatcher9+from httpx.dispatch.base import AsyncDispatcher10 11 12-class MockDispatch(Dispatcher):12+class MockDispatch(AsyncDispatcher):13 async def send(14 self,15 request: Request,16 verify: VerifyTypes = None,162 unmodified linesmodified:tests/client/test_queryparams.py+2 added-2 removed
2 unmodified lines3 import pytest4 5 from httpx import URL, AsyncClient, QueryParams, Request, Response6 from httpx.config import CertTypes, TimeoutTypes, VerifyTypes7-from httpx.dispatch.base import Dispatcher7+from httpx.dispatch.base import AsyncDispatcher8 9 10-class MockDispatch(Dispatcher):10+class MockDispatch(AsyncDispatcher):11 async def send(12 self,13 request: Request,14 verify: VerifyTypes = None,37 unmodified linesmodified:tests/client/test_redirects.py+3 added-3 removed
13 unmodified lines14 TooManyRedirects,15 codes,16 )17 from httpx.config import CertTypes, TimeoutTypes, VerifyTypes18-from httpx.dispatch.base import Dispatcher18+from httpx.dispatch.base import AsyncDispatcher19 20 21-class MockDispatch(Dispatcher):21+class MockDispatch(AsyncDispatcher):22 async def send(23 self,24 request: Request,25 verify: VerifyTypes = None,278 unmodified lines304 response = await client.get(url)305 assert response.url == URL("https://www.example.org/cross_subdomain")306 307 308-class MockCookieDispatch(Dispatcher):308+class MockCookieDispatch(AsyncDispatcher):309 async def send(310 self,311 request: Request,312 verify: VerifyTypes = None,62 unmodified linesmodified:tests/test_multipart.py+2 added-2 removed
7 unmodified lines8 9 import httpx10 from httpx.config import CertTypes, TimeoutTypes, VerifyTypes11 from httpx.content_streams import encode12-from httpx.dispatch.base import Dispatcher12+from httpx.dispatch.base import AsyncDispatcher13 from httpx.utils import format_form_param14 15 16-class MockDispatch(Dispatcher):16+class MockDispatch(AsyncDispatcher):17 async def send(18 self,19 request: httpx.Request,20 verify: VerifyTypes = None,181 unmodified lines