o
    ë6Wj  ã                   @   sn   d dl mZ d dlmZ d dlZd dlZeddd�ZG dd„ dejƒZeƒ Z	G dd	„ d	e
ƒZd
efdd„ZdS )é    )Ú
ContextVar)ÚOptionalNÚcurrent_async_library_cvar)Údefaultc                   @   s   e Zd ZdZdS )Ú_ThreadLocalN)Ú__name__Ú
__module__Ú__qualname__Úname© r   r   ú\/home/esfera/Documents/content_generation/venv/lib/python3.10/site-packages/sniffio/_impl.pyr      s    r   c                   @   s   e Zd ZdS )ÚAsyncLibraryNotFoundErrorN)r   r   r	   r   r   r   r   r      s    r   Úreturnc                  C   s®   t j} | dur	| S t ¡ } | dur| S dtjv rCddl}z|j}W n ty.   |j	j}Y nw z
|ƒ dur8W dS W n	 t
yB   Y nw dtjv rSddlm} |ƒ rSdS tdƒ‚)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}")

    NÚasyncior   Úcurio)Úcurio_runningz.unknown async library, or not in async context)Úthread_localr
   r   ÚgetÚsysÚmodulesr   Úcurrent_taskÚAttributeErrorÚTaskÚRuntimeErrorÚ
curio.metar   r   )Úvaluer   r   r   r   r   r   Úcurrent_async_library   s6   )

ÿ
ÿÿ
ÿr   )Úcontextvarsr   Útypingr   r   Ú	threadingr   Úlocalr   r   r   r   Ústrr   r   r   r   r   Ú<module>   s    ÿ