o
    ý§Ýjˆ  ã                   @  s   U d dl mZ dZd dlZd dlmZ d dlmZ d dlm	Z	m
Z
mZmZmZmZmZ d dlmZ dd	lmZ e	r?dd
lmZ edƒZedƒZd$dd„Zd$dd„Zd$dd„Zeeddd�G dd„ dƒƒƒZd%dd„Zeƒ Zded< G dd„ dejƒZ G d d!„ d!ee ƒZ!G d"d#„ d#ee ƒZ"dS )&é    )Úannotations)ÚEventLoopTokenÚRunVarÚRunvarTokenÚcancel_shielded_checkpointÚ
checkpointÚcheckpoint_if_cancelledÚcurrent_tokenN)Ú	dataclass)ÚTracebackType)ÚTYPE_CHECKINGÚAnyÚGenericÚLiteralÚTypeVarÚfinalÚoverload)ÚWeakKeyDictionaryé   )Úget_async_backend)ÚAsyncBackendÚTÚDÚreturnÚNonec                   Ã  ó   �t ƒ  ¡ I dH  dS )zò
    Check for cancellation and allow the scheduler to switch to another task.

    Equivalent to (but more efficient than)::

        await checkpoint_if_cancelled()
        await cancel_shielded_checkpoint()

    .. versionadded:: 3.0

    N)r   r   © r   r   úI/var/www/html/chatgpt/venv/lib/python3.10/site-packages/anyio/lowlevel.pyr      ó   €r   c                   Ã  r   )z°
    Enter a checkpoint if the enclosing cancel scope has been cancelled.

    This does not allow the scheduler to switch to a different task.

    .. versionadded:: 3.0

    N)r   r   r   r   r   r   r   +   s   €	r   c                   Ã  r   )zü
    Allow the scheduler to switch to another task but without checking for cancellation.

    Equivalent to (but potentially more efficient than)::

        with CancelScope(shield=True):
            await checkpoint()

    .. versionadded:: 3.0

    N)r   r   r   r   r   r   r   7   r   r   TF)ÚfrozenÚreprc                   @  s"   e Zd ZU dZded< ded< dS )r   za
    An opaque object that holds a reference to an event loop.

    .. versionadded:: 4.11.0
    ztype[AsyncBackend]Úbackend_classÚobjectÚnative_tokenN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r   r   r   r   r   F   s   
 r   c                  C  s   t ƒ } |  ¡ }t| |ƒS )zÿ
    Return a token object that can be used to call code in the current event loop from
    another thread.

    :raises NoEventLoopError: if no supported asynchronous event loop is running in the
        current thread

    .. versionadded:: 4.11.0

    )r   r	   r   )r!   Z	raw_tokenr   r   r   r	   S   s   
r	   z1WeakKeyDictionary[object, dict[RunVar[Any], Any]]Ú	_run_varsc                   @  s   e Zd Ze ¡ ZdS )Ú_NoValueSetN)r$   r%   r&   ÚenumÚautoÚNO_VALUE_SETr   r   r   r   r*   f   s    r*   c                   @  s2   e Zd ZdZdZddd„Zddd„Zddd„ZdS )r   zù
    A token that can be used to restore a :class:`RunVar` to its previous value.

    Returned by :meth:`RunVar.set`. Can be used as a context manager to automatically
    reset the variable on exit, or passed directly to :meth:`RunVar.reset`.
    )Ú	_redeemedÚ_valueÚ_varÚvarú	RunVar[T]Úvalueú%T | Literal[_NoValueSet.NO_VALUE_SET]c                 C  s   || _ || _d| _d S )NF)r0   r/   r.   )Úselfr1   r3   r   r   r   Ú__init__t   s   
zRunvarToken.__init__r   úRunvarToken[T]c                 C  s   | S ©Nr   ©r5   r   r   r   Ú	__enter__y   ó   zRunvarToken.__enter__Úexc_typeútype[BaseException] | NoneÚexc_valúBaseException | NoneÚexc_tbúTracebackType | Noner   c                 C  s   | j  | ¡ d S r8   )r0   Úreset)r5   r<   r>   r@   r   r   r   Ú__exit__|   s   zRunvarToken.__exit__N)r1   r2   r3   r4   )r   r7   )r<   r=   r>   r?   r@   rA   r   r   )r$   r%   r&   r'   Ú	__slots__r6   r:   rC   r   r   r   r   r   j   s    

r   c                   @  sˆ   e Zd ZU dZdZejZded< efd"d	d
„Ze	d#dd„ƒZ
ed$dd„ƒZed%dd„ƒZefd&dd„Zd'dd„Zd(dd„Zd)dd „Zd!S )*r   a  
    Like a :class:`~contextvars.ContextVar`, except scoped to the running event loop.

    Can be used as a context manager, Just like :class:`~contextvars.ContextVar`, that
    will reset the variable to its previous value when the context block is exited.
    )Ú_defaultÚ_namez!Literal[_NoValueSet.NO_VALUE_SET]r-   ÚnameÚstrÚdefaultr4   c                 C  s   || _ || _d S r8   )rF   rE   )r5   rG   rI   r   r   r   r6   ‘   s   
zRunVar.__init__r   údict[RunVar[T], T]c                 C  s6   t ƒ j}zt| W S  ty   i  }t|< | Y S w r8   )r	   r#   r)   ÚKeyError)r5   r#   Zrun_varsr   r   r   Ú_current_vars—   s   
þzRunVar._current_varsr   úT | Dc                 C  ó   d S r8   r   ©r5   rI   r   r   r   Úget    r;   z
RunVar.getr   c                 C  rN   r8   r   r9   r   r   r   rP   £   r;   ú%D | Literal[_NoValueSet.NO_VALUE_SET]c                 C  sZ   z| j |  W S  ty#   |tjur| Y S | jtjur!| j Y S Y nw td| j› d�ƒ‚)a2  
        Return the current value of this run variable.

        :param default: a fallback value to return if no value has been set
        :return: the current value, the provided default, or the variable's own default
        :raises LookupError: if no value is set and no default is available

        zRun variable "z!" has no value and no default set)rL   rK   r   r-   rE   ÚLookupErrorrF   rO   r   r   r   rP   ¦   s   

ÿýÿr3   r7   c                 C  s&   | j }t| | | tj¡ƒ}||| < |S )z¾
        Set the value of this run variable for the current event loop.

        :param value: the new value
        :return: a token that can be used to restore the previous value

        )rL   r   rP   r   r-   )r5   r3   Zcurrent_varsÚtokenr   r   r   Úset½   s   z
RunVar.setrS   r   c                 C  sb   |j | ur	tdƒ‚|jrtdƒ‚|jtju r&z| j| = W n ty%   Y nw |j| j| < d|_dS )a  
        Restore this run variable to the value it held before the matching :meth:`set`.

        :param token: the token returned by :meth:`set`
        :raises ValueError: if the token belongs to a different :class:`RunVar` or the token
            has already been used

        z)This token does not belong to this RunVarz This token has already been usedTN)r0   Ú
ValueErrorr.   r/   r*   r-   rL   rK   )r5   rS   r   r   r   rB   Ê   s   
	ÿ
zRunVar.resetc                 C  s   d| j ›d�S )Nz<RunVar name=ú>)rF   r9   r   r   r   Ú__repr__ã   s   zRunVar.__repr__N)rG   rH   rI   r4   )r   rJ   )rI   r   r   rM   )r   r   )rI   rQ   r   rM   )r3   r   r   r7   )rS   r7   r   r   )r   rH   )r$   r%   r&   r'   rD   r*   r-   r(   r6   ÚpropertyrL   r   rP   rT   rB   rW   r   r   r   r   r   …   s"   
 ÿÿ

r   )r   r   )r   r   )#Ú
__future__r   Ú__all__r+   Údataclassesr
   Útypesr   Útypingr   r   r   r   r   r   r   Úweakrefr   Z_core._eventloopr   Úabcr   r   r   r   r   r   r   r	   r)   r(   ÚEnumr*   r   r   r   r   r   r   Ú<module>   s.    
$




