zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
U
Z±d ã@snddlmZddlmZddlZddlZedddZGdd„dejƒZeƒZ    Gdd    „d    e
ƒZ e d
œd d „Z dS) é)Ú
ContextVar)ÚOptionalNÚcurrent_async_library_cvar)Údefaultc@seZdZdZdS)Ú _ThreadLocalN)Ú__name__Ú
__module__Ú __qualname__Úname©r r úDd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\sniffio/_impl.pyr src@s eZdZdS)ÚAsyncLibraryNotFoundErrorN)rrr    r r r r r sr )ÚreturncCs¶tj}|dk    r|St ¡}|dk    r&|SdtjkrŠddl}z
|j}Wntk
r^|j    j}YnXz|ƒdk    rrWdSWnt
k
rˆYnXdtjkrªddl m }|ƒrªdSt dƒ‚dS)aeDetect which async library is currently running.
 
    The following libraries are currently supported:
 
    ================   ===========  ============================
    Library             Requires     Magic string
    ================   ===========  ============================
    **Trio**            Trio v0.6+   ``"trio"``
    **Curio**           -            ``"curio"``
    **asyncio**                      ``"asyncio"``
    **Trio-asyncio**    v0.8.2+     ``"trio"`` or ``"asyncio"``,
                                    depending on current mode
    ================   ===========  ============================
 
    Returns:
      A string like ``"trio"``.
 
    Raises:
      AsyncLibraryNotFoundError: if called from synchronous context,
        or if the current async library was not recognized.
 
    Examples:
 
        .. code-block:: python3
 
           from sniffio import current_async_library
 
           async def generic_sleep(seconds):
               library = current_async_library()
               if library == "trio":
                   import trio
                   await trio.sleep(seconds)
               elif library == "asyncio":
                   import asyncio
                   await asyncio.sleep(seconds)
               # ... and so on ...
               else:
                   raise RuntimeError(f"Unsupported library {library!r}")
 
    NÚasynciorZcurio)Ú curio_runningz.unknown async library, or not in async context)Ú thread_localr
rÚgetÚsysÚmodulesrÚ current_taskÚAttributeErrorZTaskÚ RuntimeErrorZ
curio.metarr )Úvaluerrrr r r Úcurrent_async_librarys0)
 
 
 
 
 ÿr)Z contextvarsrÚtypingrrÚ    threadingrÚlocalrrrr Ústrrr r r r Ú<module>s  ÿ