concurrency.py
This file
Path
tests/concurrency.py
77 lines · 2.0 KiB · Python
Last changed by
Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a
History of this fileTake it
The walk stopped after 200 commits: lines older than 8155352 point at it.
Document digest auth (#348)Yeray Diaz Diazbefore adoption8155352
lines 1–7why, one step back1"""2This module contains concurrency utilities that are only used in tests, thus not3required as part of the ConcurrencyBackend API.4"""56import asyncio7import functoolsFix race condition on stream.read (#535)Florimond Mancabefore adoptiona05ba2e
line 8why, one step back8import typingDocument digest auth (#348)Yeray Diaz Diazbefore adoption8155352
line 9why, one step back9Fix race condition on stream.read (#535)Florimond Mancabefore adoptiona05ba2e
lines 10–11why, one step back10import trio11Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a
lines 12–14why, one step back12from httpx.backends.asyncio import AsyncioBackend13from httpx.backends.auto import AutoBackend14from httpx.backends.trio import TrioBackendDocument digest auth (#348)Yeray Diaz Diazbefore adoption8155352
lines 15–21why, one step back151617@functools.singledispatch18async def sleep(backend, seconds: int):19 raise NotImplementedError # pragma: no cover2021Refactor tests in the light of backend auto-detection (#615)Florimond Mancabefore adoptionab41a5d
lines 22–26why, one step back22@sleep.register(AutoBackend)23async def _sleep_auto(backend, seconds: int):24 return await sleep(backend.backend, seconds=seconds)2526Document digest auth (#348)Yeray Diaz Diazbefore adoption8155352
lines 27–29why, one step back27@sleep.register(AsyncioBackend)28async def _sleep_asyncio(backend, seconds: int):29 await asyncio.sleep(seconds)Add trio concurrency backend (#276)Florimond Mancabefore adoption08355c6
lines 30–31why, one step back3031Fix race condition on stream.read (#535)Florimond Mancabefore adoptiona05ba2e
lines 32–34why, one step back32@sleep.register(TrioBackend)33async def _sleep_trio(backend, seconds: int):34 await trio.sleep(seconds)Add trio concurrency backend (#276)Florimond Mancabefore adoption08355c6
line 35why, one step back35Fix race condition on stream.read (#535)Florimond Mancabefore adoptiona05ba2e
lines 36–41why, one step back3637@functools.singledispatch38async def run_concurrently(backend, *coroutines: typing.Callable[[], typing.Awaitable]):39 raise NotImplementedError # pragma: no cover4041Refactor tests in the light of backend auto-detection (#615)Florimond Mancabefore adoptionab41a5d
lines 42–46why, one step back42@run_concurrently.register(AutoBackend)43async def _run_concurrently_auto(backend, *coroutines):44 await run_concurrently(backend.backend, *coroutines)4546Fix race condition on stream.read (#535)Florimond Mancabefore adoptiona05ba2e
lines 47–57why, one step back47@run_concurrently.register(AsyncioBackend)48async def _run_concurrently_asyncio(backend, *coroutines):49 coros = (coroutine() for coroutine in coroutines)50 await asyncio.gather(*coros)515253@run_concurrently.register(TrioBackend)54async def _run_concurrently_trio(backend, *coroutines):55 async with trio.open_nursery() as nursery:56 for coroutine in coroutines:57 nursery.start_soon(coroutine)Refactor tests in the light of backend auto-detection (#615)Florimond Mancabefore adoptionab41a5d
lines 58–77why, one step back585960@functools.singledispatch61def get_cipher(backend, stream):62 raise NotImplementedError # pragma: no cover636465@get_cipher.register(AutoBackend)66def _get_cipher_auto(backend, stream):67 return get_cipher(backend.backend, stream)686970@get_cipher.register(AsyncioBackend)71def _get_cipher_asyncio(backend, stream):72 return stream.stream_writer.get_extra_info("cipher", default=None)737475@get_cipher.register(TrioBackend)76def get_trio_cipher(backend, stream):77 return stream.stream.cipher() if isinstance(stream.stream, trio.SSLStream) else None