From: Florimond Manca Date: Wed, 21 Aug 2019 07:02:04 +0000 (+0200) Subject: Add BaseEvent interface (#260) X-Git-Tag: 0.7.2~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2e91d8ccddcb7306412916d6731585cd510b4c73;p=thirdparty%2Fhttpx.git Add BaseEvent interface (#260) --- diff --git a/httpx/concurrency/asyncio.py b/httpx/concurrency/asyncio.py index f378e4d9..8fa19e9f 100644 --- a/httpx/concurrency/asyncio.py +++ b/httpx/concurrency/asyncio.py @@ -17,6 +17,7 @@ from types import TracebackType from .base import ( BaseBackgroundManager, BasePoolSemaphore, + BaseEvent, BaseQueue, BaseReader, BaseWriter, @@ -219,6 +220,9 @@ class AsyncioBackend(ConcurrencyBackend): def create_queue(self, max_size: int) -> BaseQueue: return typing.cast(BaseQueue, asyncio.Queue(maxsize=max_size)) + def create_event(self) -> BaseEvent: + return typing.cast(BaseEvent, asyncio.Event()) + def background_manager( self, coroutine: typing.Callable, args: typing.Any ) -> "BackgroundManager": diff --git a/httpx/concurrency/base.py b/httpx/concurrency/base.py index 1a6842b8..077961d2 100644 --- a/httpx/concurrency/base.py +++ b/httpx/concurrency/base.py @@ -82,6 +82,21 @@ class BaseQueue: raise NotImplementedError() # pragma: no cover +class BaseEvent: + """ + An event object. Abstracts away any asyncio-specific interfaces. + """ + + def set(self) -> None: + raise NotImplementedError() # pragma: no cover + + def is_set(self) -> bool: + raise NotImplementedError() # pragma: no cover + + async def wait(self) -> None: + raise NotImplementedError() # pragma: no cover + + class BasePoolSemaphore: """ A semaphore for use with connection pooling. @@ -145,6 +160,9 @@ class ConcurrencyBackend: def create_queue(self, max_size: int) -> BaseQueue: raise NotImplementedError() # pragma: no cover + def create_event(self) -> BaseEvent: + raise NotImplementedError() # pragma: no cover + def background_manager( self, coroutine: typing.Callable, args: typing.Any ) -> "BaseBackgroundManager": diff --git a/httpx/dispatch/asgi.py b/httpx/dispatch/asgi.py index bf926f48..589bf8c8 100644 --- a/httpx/dispatch/asgi.py +++ b/httpx/dispatch/asgi.py @@ -82,7 +82,7 @@ class ASGIDispatch(AsyncDispatcher): app_exc = None status_code = None headers = None - response_started_or_failed = asyncio.Event() + response_started_or_failed = self.backend.create_event() response_body = BodyIterator(self.backend) request_stream = request.stream()