Dispatcher -> AsyncDispatcher (#725)

* Dispatcher -> AsyncDispatcher

* Fix invalid renamings

* Fix invalid renamings
This commit is contained in:
Tom Christie 2020-01-06 12:08:14 +00:00 committed by GitHub
parent 6ac49dacdd
commit e19bd9bc4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 38 additions and 37 deletions

View File

@ -21,7 +21,7 @@ from .config import (
)
from .content_streams import ContentStream
from .dispatch.asgi import ASGIDispatch
from .dispatch.base import Dispatcher
from .dispatch.base import AsyncDispatcher
from .dispatch.connection_pool import ConnectionPool
from .dispatch.proxy_http import HTTPProxy
from .exceptions import (
@ -120,7 +120,7 @@ class AsyncClient:
pool_limits: PoolLimits = DEFAULT_POOL_LIMITS,
max_redirects: int = DEFAULT_MAX_REDIRECTS,
base_url: URLTypes = None,
dispatch: Dispatcher = None,
dispatch: AsyncDispatcher = None,
app: typing.Callable = None,
backend: typing.Union[str, ConcurrencyBackend] = "auto",
trust_env: bool = True,
@ -161,7 +161,7 @@ class AsyncClient:
if proxies is None and trust_env:
proxies = typing.cast(ProxiesTypes, get_environment_proxies())
self.proxies: typing.Dict[str, Dispatcher] = _proxies_to_dispatchers(
self.proxies: typing.Dict[str, AsyncDispatcher] = _proxies_to_dispatchers(
proxies,
verify=verify,
cert=cert,
@ -621,9 +621,9 @@ class AsyncClient:
return response
def dispatcher_for_url(self, url: URL) -> Dispatcher:
def dispatcher_for_url(self, url: URL) -> AsyncDispatcher:
"""
Returns the Dispatcher instance that should be used for a given URL.
Returns the AsyncDispatcher instance that should be used for a given URL.
This will either be the standard connection pool, or a proxy.
"""
if self.proxies:
@ -641,8 +641,7 @@ class AsyncClient:
)
for proxy_key in proxy_keys:
if proxy_key and proxy_key in self.proxies:
dispatcher = self.proxies[proxy_key]
return dispatcher
return self.proxies[proxy_key]
return self.dispatch
@ -897,8 +896,8 @@ def _proxies_to_dispatchers(
pool_limits: PoolLimits,
backend: typing.Union[str, ConcurrencyBackend],
trust_env: bool,
) -> typing.Dict[str, Dispatcher]:
def _proxy_from_url(url: URLTypes) -> Dispatcher:
) -> typing.Dict[str, AsyncDispatcher]:
def _proxy_from_url(url: URLTypes) -> AsyncDispatcher:
nonlocal verify, cert, http2, pool_limits, backend, trust_env
url = URL(url)
if url.scheme in ("http", "https"):
@ -917,7 +916,7 @@ def _proxies_to_dispatchers(
return {}
elif isinstance(proxies, (str, URL)):
return {"all": _proxy_from_url(proxies)}
elif isinstance(proxies, Dispatcher):
elif isinstance(proxies, AsyncDispatcher):
return {"all": proxies}
else:
new_proxies = {}

View File

@ -3,12 +3,12 @@ import typing
from ..config import TimeoutTypes
from ..content_streams import ByteStream
from ..models import Request, Response
from .base import Dispatcher
from .base import AsyncDispatcher
class ASGIDispatch(Dispatcher):
class ASGIDispatch(AsyncDispatcher):
"""
A custom dispatcher that handles sending requests directly to an ASGI app.
A custom AsyncDispatcher that handles sending requests directly to an ASGI app.
The simplest way to use this functionality is to use the `app` argument.
This will automatically infer if 'app' is a WSGI or an ASGI application,

View File

@ -12,12 +12,12 @@ from ..models import (
)
class Dispatcher:
class AsyncDispatcher:
"""
Base class for dispatcher classes, that handle sending the request.
Base class for AsyncDispatcher classes, that handle sending the request.
Stubs out the interface, as well as providing a `.request()` convenience
implementation, to make it easy to use or test stand-alone dispatchers,
implementation, to make it easy to use or test stand-alone AsyncDispatchers,
without requiring a complete `AsyncClient` instance.
"""
@ -40,7 +40,7 @@ class Dispatcher:
async def close(self) -> None:
pass # pragma: nocover
async def __aenter__(self) -> "Dispatcher":
async def __aenter__(self) -> "AsyncDispatcher":
return self
async def __aexit__(

View File

@ -7,7 +7,7 @@ from ..backends.base import ConcurrencyBackend, lookup_backend
from ..config import SSLConfig, Timeout
from ..models import URL, Origin, Request, Response
from ..utils import get_logger
from .base import Dispatcher
from .base import AsyncDispatcher
from .http2 import HTTP2Connection
from .http11 import HTTP11Connection
@ -18,7 +18,7 @@ ReleaseCallback = typing.Callable[["HTTPConnection"], typing.Awaitable[None]]
logger = get_logger(__name__)
class HTTPConnection(Dispatcher):
class HTTPConnection(AsyncDispatcher):
def __init__(
self,
origin: typing.Union[str, Origin],

View File

@ -12,7 +12,7 @@ from ..config import (
from ..exceptions import PoolTimeout
from ..models import Origin, Request, Response
from ..utils import get_logger
from .base import Dispatcher
from .base import AsyncDispatcher
from .connection import HTTPConnection
CONNECTIONS_DICT = typing.Dict[Origin, typing.List[HTTPConnection]]
@ -85,7 +85,7 @@ class ConnectionStore:
return len(self.all)
class ConnectionPool(Dispatcher):
class ConnectionPool(AsyncDispatcher):
KEEP_ALIVE_EXPIRY = 5.0
def __init__(

View File

@ -52,7 +52,7 @@ from .utils import (
)
if typing.TYPE_CHECKING: # pragma: no cover
from .dispatch.base import Dispatcher # noqa: F401
from .dispatch.base import AsyncDispatcher # noqa: F401
PrimitiveData = typing.Optional[typing.Union[str, int, float, bool]]
@ -74,7 +74,9 @@ HeaderTypes = typing.Union[
CookieTypes = typing.Union["Cookies", CookieJar, typing.Dict[str, str]]
ProxiesTypes = typing.Union[
URLTypes, "Dispatcher", typing.Dict[URLTypes, typing.Union[URLTypes, "Dispatcher"]]
URLTypes,
"AsyncDispatcher",
typing.Dict[URLTypes, typing.Union[URLTypes, "AsyncDispatcher"]],
]

View File

@ -16,10 +16,10 @@ from httpx import (
)
from httpx.auth import Auth, AuthFlow
from httpx.config import CertTypes, TimeoutTypes, VerifyTypes
from httpx.dispatch.base import Dispatcher
from httpx.dispatch.base import AsyncDispatcher
class MockDispatch(Dispatcher):
class MockDispatch(AsyncDispatcher):
def __init__(self, auth_header: str = "", status_code: int = 200) -> None:
self.auth_header = auth_header
self.status_code = status_code
@ -38,7 +38,7 @@ class MockDispatch(Dispatcher):
)
class MockDigestAuthDispatch(Dispatcher):
class MockDigestAuthDispatch(AsyncDispatcher):
def __init__(
self,
algorithm: str = "SHA-256",

View File

@ -5,10 +5,10 @@ import pytest
from httpx import AsyncClient, Cookies, Request, Response
from httpx.config import CertTypes, TimeoutTypes, VerifyTypes
from httpx.dispatch.base import Dispatcher
from httpx.dispatch.base import AsyncDispatcher
class MockDispatch(Dispatcher):
class MockDispatch(AsyncDispatcher):
async def send(
self,
request: Request,

View File

@ -6,10 +6,10 @@ import pytest
from httpx import AsyncClient, Headers, Request, Response, __version__
from httpx.config import CertTypes, TimeoutTypes, VerifyTypes
from httpx.dispatch.base import Dispatcher
from httpx.dispatch.base import AsyncDispatcher
class MockDispatch(Dispatcher):
class MockDispatch(AsyncDispatcher):
async def send(
self,
request: Request,

View File

@ -4,10 +4,10 @@ import pytest
from httpx import URL, AsyncClient, QueryParams, Request, Response
from httpx.config import CertTypes, TimeoutTypes, VerifyTypes
from httpx.dispatch.base import Dispatcher
from httpx.dispatch.base import AsyncDispatcher
class MockDispatch(Dispatcher):
class MockDispatch(AsyncDispatcher):
async def send(
self,
request: Request,

View File

@ -15,10 +15,10 @@ from httpx import (
codes,
)
from httpx.config import CertTypes, TimeoutTypes, VerifyTypes
from httpx.dispatch.base import Dispatcher
from httpx.dispatch.base import AsyncDispatcher
class MockDispatch(Dispatcher):
class MockDispatch(AsyncDispatcher):
async def send(
self,
request: Request,
@ -305,7 +305,7 @@ async def test_cross_subdomain_redirect():
assert response.url == URL("https://www.example.org/cross_subdomain")
class MockCookieDispatch(Dispatcher):
class MockCookieDispatch(AsyncDispatcher):
async def send(
self,
request: Request,

View File

@ -9,11 +9,11 @@ import pytest
import httpx
from httpx.config import CertTypes, TimeoutTypes, VerifyTypes
from httpx.content_streams import encode
from httpx.dispatch.base import Dispatcher
from httpx.dispatch.base import AsyncDispatcher
from httpx.utils import format_form_param
class MockDispatch(Dispatcher):
class MockDispatch(AsyncDispatcher):
async def send(
self,
request: httpx.Request,