o
     dG                     @   s*  U d dl Z d dl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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efddZe Zi Zeedf 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 )     N)	dataclass)AnyDictGenericSetTypeVarUnionoverload)WeakKeyDictionary   )get_asynclib)      )LiteralTDreturnc                         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   9/usr/local/lib/python3.10/dist-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   -   r   r   c                   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   _TokenWrapper_token_wrappersT)frozenc                   @   s   e Zd ZU dZeed< dS )r   )_token__weakref__r   N)__name__
__module____qualname__	__slots__object__annotations__r   r   r   r   r   E   s   
 c                   @   s   e Zd Ze ZdS )_NoValueSetN)r    r!   r"   enumautoNO_VALUE_SETr   r   r   r   r&   K   s    r&   c                   @   s0   e Zd ZdZdddeeeej f fddZ	dS )RunvarToken_var_value	_redeemedvarz	RunVar[T]valuec                 C   s   || _ || _d| _d S )NFr+   )selfr/   r0   r   r   r   __init__R   s   
zRunvarToken.__init__N)
r    r!   r"   r#   r   r   r   r&   r)   r2   r   r   r   r   r*   O   s    r*   c                   @   s  e Zd ZU dZdZejZeej ed< e	 Z
ee ed< efdedeeeej f fddZed	eeef fd
dZeded	eeef fddZed	efddZefdeeeej f d	eeef fddZded	ee fddZ	dee d	dfddZd	efddZdS )RunVarzQLike a :class:`~contextvars.ContextVar`, expect scoped to the running event loop._name_defaultr)   r   namedefaultc                 C   s   || _ || _d S Nr4   )r1   r7   r8   r   r   r   r2   c   s   
zRunVar.__init__r   c                 C   s\   t  }	 zt| W S  ty   t|}| j| Y n ty,   i  }t|< | Y S w qr9   )r   	_run_vars	TypeErrorr   r   addKeyError)r1   tokenrun_varsr   r   r   _current_varsk   s   
zRunVar._current_varsc                 C      d S r9   r   r1   r8   r   r   r   get{      z
RunVar.getc                 C   rA   r9   r   r1   r   r   r   rC      rD   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)r@   r5   r=   r3   r)   r6   LookupErrorrB   r   r   r   rC      s   

r0   c                 C   s*   | j }t| || jtj}||| j< |S r9   )r@   r*   rC   r5   r3   r)   )r1   r0   current_varsr>   r   r   r   set   s   
z
RunVar.setr>   Nc                 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)   r@   r5   r=   )r1   r>   r   r   r   reset   s   

zRunVar.resetc                 C   s   d| j dS )Nz<RunVar name=>)r5   rE   r   r   r   __repr__   s   zRunVar.__repr__)r    r!   r"   __doc__r#   r&   r)   r   r%   rH   r   r   r   strr   r   r2   propertyr   r@   r	   r   rC   r*   rJ   rL   r   r   r   r   r3   Z   s4   
 


r3   )r   N)"r'   sysdataclassesr   typingr   r   r   r   r   r   r	   weakrefr
   _core._eventloopr   version_infor   typing_extensionsr   r   r   r   r   r$   r   r:   r   r%   r   Enumr&   r*   r3   r   r   r   r   <module>   s,   
 $



