U
    &%e'                     @  s6  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rrd d	lmZ n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d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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
   
checkpoint r   r   M/var/www/html/Darija-Ai-API/env/lib/python3.8/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
   checkpoint_if_cancelledr   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
   cancel_shielded_checkpointr   r   r   r   r   0   s    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ddZdS )RunvarToken_var_value	_redeemedz	RunVar[T]%T | Literal[_NoValueSet.NO_VALUE_SET])varvaluec                 C  s   || _ || _d| _d S )NFr*   )selfr/   r0   r   r   r   __init__V   s    zRunvarToken.__init__N)r    r!   r"   r#   r2   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	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 )$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   strr.   )namedefaultc                 C  s   || _ || _d S Nr4   )r1   r8   r9   r   r   r   r2   g   s    zRunVar.__init__zdict[str, T]r   c                 C  sb   t  }z
t| W S  tk
r8   t|}| j| Y q tk
rZ   i  }t|< | Y S X qd S r:   )r   r   	TypeErrorr   r   addKeyError)r1   tokenZrun_varsr   r   r   _current_varso   s    
zRunVar._current_varsr   zT | D)r9   r   c                 C  s   d S r:   r   r1   r9   r   r   r   get   s    z
RunVar.getr   c                 C  s   d S r:   r   r1   r   r   r   rA      s    z%D | Literal[_NoValueSet.NO_VALUE_SET]c                 C  sb   z| j | j W S  tk
rJ   |tjk	r0| Y S | jtjk	rF| j Y S Y nX td| j dd S )NzRun variable "z!" has no value and no default set)r?   r5   r=   r3   r(   r6   LookupErrorr@   r   r   r   rA      s    
zRunvarToken[T])r0   r   c                 C  s*   | j }t| || jtj}||| j< |S r:   )r?   r)   rA   r5   r3   r(   )r1   r0   Zcurrent_varsr>   r   r   r   set   s    
z
RunVar.setr   )r>   r   c                 C  sj   |j | k	rtd|jr td|jtjkrRz| j| j= W q` tk
rN   Y q`X n|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   rB   r   r   r   __repr__   s    zRunVar.__repr__N)r    r!   r"   __doc__r#   r%   r(   r$   rD   r   r2   propertyr?   r   rA   rF   rH   r   r   r   r   r3   \   s"   
r3   ) 
__future__r   r&   sysdataclassesr   typingr   r   r   r   weakrefr   Z_core._eventloopr
   version_infor   Ztyping_extensionsr   r   r   r   r   r   r   r$   r   r   Enumr%   r)   r3   r   r   r   r   <module>   s.    
	