
    ցj                       % S SK Jr  SrS SKrS SKJr  S SKJr  S SKJ	r	J
r
JrJrJrJrJr  S SKJr  SS	KJr  \	(       a  SS
KJr  \" S5      r\" S5      rSS jrSS jrSS jr\\" SSS9 " S S5      5       5       rSS jr\" 5       rS\S'    " S S\R>                  5      r  " S S\\   5      r! " S S\\   5      r"g)     )annotations)EventLoopTokenRunvarTokenRunVar
checkpointcheckpoint_if_cancelledcancel_shielded_checkpointcurrent_tokenN)	dataclass)TracebackType)TYPE_CHECKINGAnyGenericLiteralTypeVarfinaloverload)WeakKeyDictionary   )get_async_backend)AsyncBackendTDc                 P   #    [        5       R                  5       I Sh  vN   g N7f)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        H/mnt/workspace/venv-train/lib/python3.13/site-packages/anyio/lowlevel.pyr   r      s      

(
(
***   &$&c                 P   #    [        5       R                  5       I Sh  vN   g N7f)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      

5
5
777r   c                 P   #    [        5       R                  5       I Sh  vN   g N7f)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	   7   s      

8
8
:::r   TF)frozenreprc                  .    \ rS rSr% SrS\S'   S\S'   Srg)	r   F   zU
An opaque object that holds a reference to an event loop.

.. versionadded:: 4.11.0
ztype[AsyncBackend]backend_classobjectnative_tokenr   N)__name__
__module____qualname____firstlineno____doc____annotations____static_attributes__r   r   r   r   r   F   s     &%r   r   c                 L    [        5       n U R                  5       n[        X5      $ )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%   	raw_tokens     r   r
   r
   S   s%     &'M++-I-33r   z1WeakKeyDictionary[object, dict[RunVar[Any], Any]]	_run_varsc                  6    \ rS rSr\R
                  " 5       rSrg)_NoValueSetf   r   N)r(   r)   r*   r+   enumautoNO_VALUE_SETr.   r   r   r   r3   r3   f   s    99;Lr   r3   c                  J    \ rS rSrSrSrS	S jrS
S jr        SS jrSr	g)r   j   z
A token that can be used to restore a :class:`RunVar` to its previous value.

Returned by :meth:`RunVar.set`. Can be used as a context manager to automatically
reset the variable on exit, or passed directly to :meth:`RunVar.reset`.
_var_value	_redeemedc                *    Xl         X l        SU l        g )NFr:   )selfvarvalues      r   __init__RunvarToken.__init__t   s    	=Br   c                    U $ Nr   r?   s    r   	__enter__RunvarToken.__enter__y   s    r   c                :    U R                   R                  U 5        g rE   )r;   reset)r?   exc_typeexc_valexc_tbs       r   __exit__RunvarToken.__exit__|   s     			r   )r=   r<   r;   N)r@   z	RunVar[T]rA   %T | Literal[_NoValueSet.NO_VALUE_SET])returnRunvarToken[T])rK   ztype[BaseException] | NonerL   zBaseException | NonerM   zTracebackType | NonerQ   None)
r(   r)   r*   r+   r,   	__slots__rB   rG   rN   r.   r   r   r   r   r   j   sC     .I
, & %	
 
r   r   c                      \ rS rSr% SrSr\R                  rS\S'   \4   SS jjr	\
SS j5       r\SS j5       r\SS	 j5       r\4   SS
 jjrSS jrSS jrSS jrSrg)r      z
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]r7   c                    Xl         X l        g rE   rW   )r?   namedefaults      r   rB   RunVar.__init__   s     
r   c                x    [        5       R                  n [        U   $ ! [         a    0 =n[        U'   Us $ f = frE   )r
   r'   r1   KeyError)r?   r'   run_varss      r   _current_varsRunVar._current_vars   sB    $33	\** 	133Hy.O	s    99c                    g rE   r   r?   r\   s     r   get
RunVar.get   s    (+r   c                    g rE   r   rF   s    r   re   rf      s    r   c                     U R                   U    $ ! [         aE    U[        R                  La  Us $ U R                  [        R                  La  U R                  s $  Of = f[        SU R                   S35      e)a
  
Return the current value of this run variable.

:param default: a fallback value to return if no value has been set
:return: the current value, the provided default, or the variable's own default
:raises LookupError: if no value is set and no default is available

zRun variable "z!" has no value and no default set)ra   r_   r   r7   rY   LookupErrorrX   rd   s     r   re   rf      s{    	%%%d++ 	%f111f&9&99}}$ :	% TZZL(IJ
 	
s    A )A A c                x    U R                   n[        XR                  U [        R                  5      5      nXU '   U$ )z
Set the value of this run variable for the current event loop.

:param value: the new value
:return: a token that can be used to restore the previous value

)ra   r   re   r   r7   )r?   rA   current_varstokens       r   set
RunVar.set   s9     ))D"2"249L9L"MN"Tr   c                (   UR                   U La  [        S5      eUR                  (       a  [        S5      eUR                  [        R
                  L a   U R                  U 	 OUR                  U R                  U '   SUl        g! [         a     Nf = f)z
Restore this run variable to the value it held before the matching :meth:`set`.

:param token: the token returned by :meth:`set`
:raises ValueError: if the token belongs to a different :class:`RunVar` or the token
    has already been used

z)This token does not belong to this RunVarz This token has already been usedTN)r;   
ValueErrorr=   r<   r3   r7   ra   r_   )r?   rl   s     r   rJ   RunVar.reset   s     ::T!HII???@@<<;333&&t, (-||Dt$  s   B 
BBc                $    SU R                   < S3$ )Nz<RunVar name=>)rX   rF   s    r   __repr__RunVar.__repr__   s    tzznA..r   )rY   rX   N)r[   strr\   rP   )rQ   zdict[RunVar[T], T])r\   r   rQ   T | D)rQ   r   )r\   z%D | Literal[_NoValueSet.NO_VALUE_SET]rQ   rw   )rA   r   rQ   rR   )rl   rR   rQ   rS   )rQ   rv   )r(   r)   r*   r+   r,   rT   r3   r7   r-   rB   propertyra   r   re   rm   rJ   rt   r.   r   r   r   r   r      s     $I6A6N6NL3N KW  "G    + +  @L
<
	
.2/r   r   )rQ   rS   )rQ   r   )#
__future__r   __all__r5   dataclassesr   typesr   typingr   r   r   r   r   r   r   weakrefr   _core._eventloopr   abcr   r   r   r   r   r	   r   r
   r1   r-   Enumr3   r   r   r   r   r   <module>r      s    "  !  Q Q Q % /!CLCL+	8; 
$U#  $ 4  @Q?R	< R$)) '!* 6_/WQZ _/r   