a
    ”˜ë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 d dlmZ dd	lmZ dd
lmZ edƒZedƒZddœdd„Zddœdd„Zddœdd„Zeeddd�G dd„ dƒƒƒZd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ÚRunvarTokenÚRunVarÚ
checkpointÚcheckpoint_if_cancelledÚcancel_shielded_checkpointÚcurrent_tokenN)Ú	dataclass)ÚTracebackType)ÚAnyÚGenericÚLiteralÚTypeVarÚfinalÚoverload)ÚWeakKeyDictionaryé   )Úget_async_backend)ÚAsyncBackendÚTÚDÚNone©Úreturnc                   Ã  s   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   úM/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/anyio/lowlevel.pyr      s    r   c                   Ã  s   t ƒ  ¡ I dH  dS )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                   Ã  s   t ƒ  ¡ I dH  dS )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   5   s    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   D   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	   Q   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(   d   s   r(   c                   @  sB   e Zd ZdZdddœdd„Zddœd	d
„Zdddddœdd„ZdS )r   ©Ú_varÚ_valueÚ	_redeemedz	RunVar[T]ú%T | Literal[_NoValueSet.NO_VALUE_SET])ÚvarÚvaluec                 C  s   || _ || _d| _d S )NFr,   )Úselfr1   r2   r   r   r   Ú__init__k   s    zRunvarToken.__init__úRunvarToken[T]r   c                 C  s   | S ©Nr   ©r3   r   r   r   Ú	__enter__p   s    zRunvarToken.__enter__ztype[BaseException] | NonezBaseException | NonezTracebackType | Noner   )Úexc_typeÚexc_valÚexc_tbr   c                 C  s   | j  | ¡ d S r6   )r-   Úreset)r3   r9   r:   r;   r   r   r   Ú__exit__s   s    zRunvarToken.__exit__N)r"   r#   r$   Ú	__slots__r4   r8   r=   r   r   r   r   r   h   s   r   c                   @  s²   e Zd ZU dZdZejZded< efdddœdd	„Ze	d
dœdd„ƒZ
edddœdd„ƒZeddœdd„ƒZefdddœdd„Zdddœdd„Zdddœdd„Zd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.
    ©Ú_nameÚ_defaultz!Literal[_NoValueSet.NO_VALUE_SET]r+   Ústrr0   )ÚnameÚdefaultc                 C  s   || _ || _d S r6   r?   )r3   rC   rD   r   r   r   r4   ˆ   s    zRunVar.__init__zdict[RunVar[T], T]r   c                 C  s:   t ƒ j}z
t| W S  ty4   i  }t|< | Y S 0 d S r6   )r	   r!   r'   ÚKeyError)r3   r!   Zrun_varsr   r   r   Ú_current_varsŽ   s    
zRunVar._current_varsr   zT | D)rD   r   c                 C  s   d S r6   r   ©r3   rD   r   r   r   Úget—   s    z
RunVar.getr   c                 C  s   d S r6   r   r7   r   r   r   rH   š   s    z%D | Literal[_NoValueSet.NO_VALUE_SET]c                 C  s^   z| j |  W S  tyF   |tjur,| Y S | jtjurB| j Y S Y n0 td| j› d�ƒ‚d S )NzRun variable "z!" has no value and no default set)rF   rE   r   r+   rA   ÚLookupErrorr@   rG   r   r   r   rH   �   s    
ÿr5   )r2   r   c                 C  s&   | j }t| | | tj¡ƒ}||| < |S r6   )rF   r   rH   r   r+   )r3   r2   Zcurrent_varsÚtokenr   r   r   Úset¬   s    z
RunVar.setr   )rJ   r   c                 C  sd   |j | urtdƒ‚|jr tdƒ‚|jtju rNz| j| = W qZ tyJ   Y qZ0 n|j| j| < d|_d S )Nz)This token does not belong to this RunVarz This token has already been usedT)r-   Ú
ValueErrorr/   r.   r(   r+   rF   rE   )r3   rJ   r   r   r   r<   ²   s    
zRunVar.resetc                 C  s   d| j ›d�S )Nz<RunVar name=ú>)r@   r7   r   r   r   Ú__repr__Ã   s    zRunVar.__repr__N)r"   r#   r$   r%   r>   r(   r+   r&   r4   ÚpropertyrF   r   rH   rK   r<   rN   r   r   r   r   r   |   s    
ÿÿr   )"Ú
__future__r   Ú__all__r)   Zdataclassesr
   Útypesr   Útypingr   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*   
 
