o
    OÊÆh'  ã                   @  s&  U d dl mZ d dlZd dlZd dlmZ d dlmZmZm	Z	m
Z
 d dlmZ ddlmZ ejdkr9d d	lmZ nd d	lmZ e	d
ƒZe	dƒZd%dd„Zd%dd„Zd%dd„Zd&dd„Zeƒ Zded< i Zded< edd�G dd„ dƒƒZG dd „ d ejƒZG d!d"„ d"ee ƒZG d#d$„ d$ee ƒZdS )'é    )ÚannotationsN)Ú	dataclass)ÚAnyÚGenericÚTypeVarÚoverload)ÚWeakKeyDictionaryé   )Úget_asynclib)é   é   )ÚLiteralÚ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
   Ú
checkpoint© r   r   ú[/var/www/html/HyperOracle/crypto_trader/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
   Úcheckpoint_if_cancelledr   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
   Úcancel_shielded_checkpointr   r   r   r   r   0   r   r   Úobjectc                   C  s
   t ƒ  ¡ S )zVReturn a backend specific token object that can be used to get back to the event loop.)r
   Úcurrent_tokenr   r   r   r   r   @   s   
r   z&WeakKeyDictionary[Any, dict[str, Any]]Ú	_run_varszdict[Any, _TokenWrapper]Ú_token_wrappersT)Úfrozenc                   @  s   e Zd ZU dZded< dS )Ú_TokenWrapper)Ú_tokenÚ__weakref__r   r   N)Ú__name__Ú
__module__Ú__qualname__Ú	__slots__Ú__annotations__r   r   r   r   r   I   s   
 r   c                   @  s   e Zd Ze ¡ ZdS )Ú_NoValueSetN)r!   r"   r#   ÚenumÚautoÚNO_VALUE_SETr   r   r   r   r&   O   s    r&   c                   @  s   e Zd ZdZd	dd„ZdS )
ÚRunvarToken©Ú_varÚ_valueÚ	_redeemedÚvarú	RunVar[T]Úvalueú%T | Literal[_NoValueSet.NO_VALUE_SET]c                 C  s   || _ || _d| _d S )NFr+   )Úselfr/   r1   r   r   r   Ú__init__V   s   
zRunvarToken.__init__N)r/   r0   r1   r2   )r!   r"   r#   r$   r4   r   r   r   r   r*   S   s    r*   c                   @  s–   e Zd ZU dZdZejZded< eƒ 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 ),ÚRunVarz[
    Like a :class:`~contextvars.ContextVar`, except scoped to the running event loop.
    ©Ú_nameÚ_defaultz!Literal[_NoValueSet.NO_VALUE_SET]r)   zset[_TokenWrapper]r   ÚnameÚstrÚdefaultr2   c                 C  s   || _ || _d S ©Nr6   )r3   r9   r;   r   r   r   r4   g   s   
zRunVar.__init__r   údict[str, T]c                 C  s\   t ƒ }	 zt| W S  ty   t|ƒ}| j |¡ Y n ty,   i  }t|< | Y S w qr<   )r   r   Ú	TypeErrorr   r   ÚaddÚKeyError)r3   ÚtokenÚrun_varsr   r   r   Ú_current_varso   s   
þ÷zRunVar._current_varsr   úT | Dc                 C  ó   d S r<   r   ©r3   r;   r   r   r   Úget   ó   z
RunVar.getr   c                 C  rE   r<   r   ©r3   r   r   r   rG   ƒ   rH   ú%D | Literal[_NoValueSet.NO_VALUE_SET]c                 C  s\   z| j | 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�ƒ‚)NzRun variable "z!" has no value and no default set)rC   r7   r@   r5   r)   r8   ÚLookupErrorrF   r   r   r   rG   ‡   s   

ÿýÿr1   úRunvarToken[T]c                 C  s*   | j }t| | | jtj¡ƒ}||| j< |S r<   )rC   r*   rG   r7   r5   r)   )r3   r1   Úcurrent_varsrA   r   r   r   Úset–   s   
z
RunVar.setrA   r   c                 C  sf   |j | ur	tdƒ‚|jrtdƒ‚|jtju r'z| j| j= W n ty&   Y nw |j| 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)   rC   r7   r@   )r3   rA   r   r   r   Úresetœ   s   
ÿ
zRunVar.resetc                 C  s   d| j ›d�S )Nz<RunVar name=ú>)r7   rI   r   r   r   Ú__repr__­   s   zRunVar.__repr__N)r9   r:   r;   r2   )r   r=   )r;   r   r   rD   )r   r   )r;   rJ   r   rD   )r1   r   r   rL   )rA   rL   r   r   )r   r:   )r!   r"   r#   Ú__doc__r$   r&   r)   r%   rN   r   r4   ÚpropertyrC   r   rG   rP   rR   r   r   r   r   r5   \   s$   
 ýÿ

r5   )r   r   )r   r   ) Ú
__future__r   r'   ÚsysÚdataclassesr   Útypingr   r   r   r   Úweakrefr   Ú_core._eventloopr
   Úversion_infor   Útyping_extensionsr   r   r   r   r   r   r   r%   r   r   ÚEnumr&   r*   r5   r   r   r   r   Ú<module>   s.    




	