Skip to content
Myr

Add BaseQueue interface (#257)

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

authored by Florimond Manca · committed by GitHub · parent e0b523d · Browse files · 3 files+26 added−6 removed
This commit

State

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

Diff stats

3 files+26 added−6 removed

  • other:+26 added−6 removed

3 files+26 added−6 removed

modified:httpx/concurrency/asyncio.py+4 added
17 unmodified lines
18from ..exceptions import ConnectTimeout, PoolTimeout, ReadTimeout, WriteTimeout19from ..interfaces import (20 BaseBackgroundManager,21 BasePoolSemaphore,22 BaseQueue,23 BaseReader,24 BaseWriter,25 ConcurrencyBackend,26)
219 unmodified lines
246247 def get_semaphore(self, limits: PoolLimits) -> BasePoolSemaphore:248 return PoolSemaphore(limits)249250 def create_queue(self, max_size: int) -> BaseQueue:251 return typing.cast(BaseQueue, asyncio.Queue(maxsize=max_size))252253 def background_manager(254 self, coroutine: typing.Callable, args: typing.Any255 ) -> "BackgroundManager":256 return BackgroundManager(coroutine, args)
21 unmodified lines
modified:httpx/dispatch/asgi.py+7 added-6 removed
1import asyncio2import typing34from ..concurrency.asyncio import AsyncioBackend5from ..config import CertTypes, TimeoutTypes, VerifyTypes5from ..interfaces import AsyncDispatcher6from ..interfaces import AsyncDispatcher, ConcurrencyBackend7from ..models import AsyncRequest, AsyncResponse8910class ASGIDispatch(AsyncDispatcher):
41 unmodified lines
52 self.app = app53 self.raise_app_exceptions = raise_app_exceptions54 self.root_path = root_path55 self.client = client56 # This will need to be turned into a parameter on this class at some point.57 self.backend: ConcurrencyBackend = AsyncioBackend()5859 async def send(60 self,61 request: AsyncRequest,
19 unmodified lines
81 app_exc = None82 status_code = None83 headers = None84 response_started_or_failed = asyncio.Event()82 response_body = BodyIterator()85 response_body = BodyIterator(self.backend)86 request_stream = request.stream()8788 async def receive() -> dict:89 nonlocal request_stream
68 unmodified lines
158 Provides a byte-iterator interface that the client can use to159 ingest the response content from.160 """161159 def __init__(self) -> None:160 self._queue = asyncio.Queue(161 maxsize=1162 ) # type: asyncio.Queue[typing.Union[bytes, object]]162 def __init__(self, backend: ConcurrencyBackend) -> None:163 self._queue = backend.create_queue(max_size=1)164 self._done = object()165166 async def iterate(self) -> typing.AsyncIterator[bytes]:167 """
28 unmodified lines
modified:httpx/interfaces.py+15 added
143 unmodified lines
144 async def close(self) -> None:145 raise NotImplementedError() # pragma: no cover146147148class BaseQueue:149 """150 A FIFO queue. Abstracts away any asyncio-specific interfaces.151 """152153 async def get(self) -> typing.Any:154 raise NotImplementedError() # pragma: no cover155156 async def put(self, value: typing.Any) -> None:157 raise NotImplementedError() # pragma: no cover158159160class BasePoolSemaphore:161 """162 A semaphore for use with connection pooling.163
52 unmodified lines
216 yield self.run(async_iterator.__anext__)217 except StopAsyncIteration:218 break219220 def create_queue(self, max_size: int) -> BaseQueue:221 raise NotImplementedError() # pragma: no cover222223 def background_manager(224 self, coroutine: typing.Callable, args: typing.Any225 ) -> "BaseBackgroundManager":226 raise NotImplementedError() # pragma: no cover
13 unmodified lines