U
    ,hb¡
  ã                   @   sN   d dl mZ d dlmZ d dlZedddZG dd„ deƒZedœd	d
„Z	dS )é    )Ú
ContextVar)ÚOptionalNÚcurrent_async_library_cvar)Údefaultc                   @   s   e Zd ZdS )ÚAsyncLibraryNotFoundErrorN)Ú__name__Ú
__module__Ú__qualname__© r
   r
   ú1/tmp/pip-unpacked-wheel-vrtgg_qo/sniffio/_impl.pyr   
   s   r   )Úreturnc                  C   s¸   t  ¡ } | dk	r| S dtjkr4ddlm} |ƒ r4dS dtjkr¬ddl}z
|j}W n tk
rl   |j	j}Y nX z(|ƒ dk	r”dtj
krŽt  d¡ W dS W n tk
rª   Y nX tdƒ‚dS )ae  Detect 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}")

    NZcurior   )Úcurio_runningÚasyncio)é   é   z.unknown async library, or not in async context)r   ÚgetÚsysÚmodulesZ
curio.metar   r   Úcurrent_taskÚAttributeErrorZTaskÚversion_infoÚsetÚRuntimeErrorr   )Úvaluer   r   r   r
   r
   r   Úcurrent_async_library   s.    )






ÿr   )
Zcontextvarsr   Útypingr   r   r   r   r   Ústrr   r
   r
   r
   r   Ú<module>   s    ÿ