]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Dispatcher -> AsyncDispatcher (#725)
authorTom Christie <tom@tomchristie.com>
Mon, 6 Jan 2020 12:08:14 +0000 (12:08 +0000)
committerGitHub <noreply@github.com>
Mon, 6 Jan 2020 12:08:14 +0000 (12:08 +0000)
* Dispatcher -> AsyncDispatcher

* Fix invalid renamings

* Fix invalid renamings

12 files changed:
httpx/client.py
httpx/dispatch/asgi.py
httpx/dispatch/base.py
httpx/dispatch/connection.py
httpx/dispatch/connection_pool.py
httpx/models.py
tests/client/test_auth.py
tests/client/test_cookies.py
tests/client/test_headers.py
tests/client/test_queryparams.py
tests/client/test_redirects.py
tests/test_multipart.py

index 75f29ac3b7aac6e4cff0ee2c3060fc417f345105..c16912f08abd5cc1eb135bed9dc163494f2824f1 100644 (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 = {}
index 2f74019e28447ef69adee40f39e61fefcd3af597..335540b6efc6ac5a062f0252331edc7e5f121eb2 100644 (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,
index f24eb68afefafa163126c7f408bd493f93d56f22..4879ea8296508dd96f9c3fa8916975e17d17772b 100644 (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__(
index d9e104b0c88018bda745a36709cbd56abfcac3bf..9b6b28b7c964591b534da0661ef72749f7eeea22 100644 (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],
index 3e09b110175ec56102d470ecc53c072054c03b9c..4ca2e5fd69370ce429f459406811e48bf72de9f9 100644 (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__(
index dc98b302e1a8e3359cad1a4fa7f3aaf26f764f52..7f085d24f5b17b3fb6d8055cfaaca4d3d6de29ff 100644 (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"]],
 ]
 
 
index 34ec77eb4b3750c364ee1eb0f27bae14bfc49095..af9a17be4e106c79a6c0bdbf7e8d936f35e8f0a8 100644 (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",
index 3e8d0d3b18c5548540d8954934f3681c04e183d2..2932232d320444402fbb7733955f8165ce631fe1 100644 (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,
index 672092d8e8da18282899abf971ef007612f3d96e..56cf24c71fdc8031d991bc2547df77fb7f14c1b0 100755 (executable)
@@ -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,
index a887f1c2940f721c780d7e13bad38a39072e3442..e0ce45b2d2ef61fb90e2325f3f01a1d04697b44e 100644 (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,
index 4c02745532c8c5a1564db232726bbc9bad2d5748..a48e478eff96576f844c7fd11c19750a67debbba 100644 (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,
index eb1eaac41abc3a6aa4ab23772d3062e3100db59a..e0bd750cc7194b47682fa9d3e63c977e7b3f3ce1 100644 (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,