
    dh5                    \   U d dl m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 d dlmZ ddlmZ ddlmZ  e	d	      Z e	d
      ZddZddZddZe
 edd       G d d                    ZddZ e       Zded<    G d dej6                        Z G d dee         Z G d dee         Zy)    )annotationsN)	dataclass)AnyGenericLiteralTypeVarfinaloverload)WeakKeyDictionary   )get_async_backend)AsyncBackendTDc                 P   K   t               j                          d{    y7 w)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     A/var/www/zara/venv/lib/python3.12/site-packages/anyio/lowlevel.pyr   r      s      

(
(
***   &$&c                 P   K   t               j                          d{    y7 w)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      

5
5
777r   c                 P   K   t               j                          d{    y7 w)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   +   s      

8
8
:::r   TF)frozenreprc                  &    e Zd ZU dZded<   ded<   y)EventLoopTokenza
    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   ;   s     &%r   r   c                 N    t               } | j                         }t        | |      S )z
    Return a token object that can be used to call code in the current event loop from
    another thread.

    .. versionadded:: 4.11.0

    )r   current_tokenr   )r   	raw_tokens     r   r(   r(   H   s'     &'M++-I-33r   z1WeakKeyDictionary[object, dict[RunVar[Any], Any]]	_run_varsc                  .    e Zd Z ej                         Zy)_NoValueSetN)r"   r#   r$   enumautoNO_VALUE_SETr   r   r   r,   r,   X   s    499;Lr   r,   c                      e Zd ZdZddZy)RunvarToken_var_value	_redeemedc                .    || _         || _        d| _        y )NFr2   )selfvarvalues      r   __init__zRunvarToken.__init___   s    	=Br   N)r8   z	RunVar[T]r9   %T | Literal[_NoValueSet.NO_VALUE_SET])r"   r#   r$   	__slots__r:   r   r   r   r1   r1   \   s    -Ir   r1   c                      e Zd ZU dZdZej                  Zded<   ef	 	 	 ddZe	dd       Z
edd       Zedd       Zef	 	 	 dd	Zdd
ZddZddZy)RunVarz[
    Like a :class:`~contextvars.ContextVar`, except scoped to the running event loop.
    _name_defaultz!Literal[_NoValueSet.NO_VALUE_SET]r/   c                     || _         || _        y Nr?   )r7   namedefaults      r   r:   zRunVar.__init__n   s     
r   c                v    t               j                  }	 t        |   S # t        $ r i x}t        |<   |cY S w xY wrC   )r(   r!   r*   KeyError)r7   r!   run_varss      r   _current_varszRunVar._current_varst   sB    $33	\** 	133Hy.O	s    88c                     y rC   r   r7   rE   s     r   getz
RunVar.get}   s    (+r   c                     y rC   r   r7   s    r   rL   z
RunVar.get   s    r   c                    	 | j                   |    S # t        $ rC |t        j                  ur|cY S | j                  t        j                  ur| j                  cY S Y nw xY wt        d| j                   d      )NzRun variable "z!" has no value and no default set)rI   rG   r>   r/   rA   LookupErrorr@   rK   s     r   rL   z
RunVar.get   s{    	%%%d++ 	%f111f&9&99}}$ :	% TZZL(IJ
 	
s    A(AAc                |    | j                   }t        | |j                  | t        j                              }||| <   |S rC   )rI   r1   rL   r>   r/   )r7   r9   current_varstokens       r   setz
RunVar.set   s;    ))D,"2"249L9L"MN"Tr   c                4   |j                   | urt        d      |j                  rt        d      |j                  t        j
                  u r	 | j                  | = d|_        y |j                  | j                  | <   d|_        y # t        $ r
 Y d|_        y w xY w)Nz)This token does not belong to this RunVarz This token has already been usedT)r3   
ValueErrorr5   r4   r,   r/   rI   rG   )r7   rS   s     r   resetzRunVar.reset   s    ::T!HII???@@<<;333&&t,  (-||Dt$   s   B 	BBc                "    d| j                   dS )Nz<RunVar name=>)r@   rN   s    r   __repr__zRunVar.__repr__   s    tzznA..r   N)rD   strrE   r;   )returnzdict[RunVar[T], T])rE   r   r\   T | D)r\   r   )rE   z%D | Literal[_NoValueSet.NO_VALUE_SET]r\   r]   )r9   r   r\   RunvarToken[T])rS   r^   r\   None)r\   r[   )r"   r#   r$   r%   r<   r,   r/   r&   r:   propertyrI   r
   rL   rT   rW   rZ   r   r   r   r>   r>   e   s     $I6A6N6NL3N KW  "G    + +  @L
<
	
"/r   r>   )r\   r_   )r\   r   )
__future__r   r-   dataclassesr   typingr   r   r   r   r	   r
   weakrefr   _core._eventloopr   abcr   r   r   r   r   r   r   r(   r*   r&   Enumr,   r1   r>   r   r   r   <module>rh      s    "  ! B B % / CLCL+ 	8;  
$U#  $ 
4 @Q?R	< R$)) '!* E/WQZ E/r   