
    > /i                    l   U d dl mZ dZd dlZd dlm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j<                        Z G d de
e         Z  G d de
e         Z!y)     )annotations)EventLoopTokenRunvarTokenRunVar
checkpointcheckpoint_if_cancelledcancel_shielded_checkpointcurrent_tokenN)	dataclass)TracebackType)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   r        D/srv/sistema/bot/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   r   r   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   r	   r   r   r   r	   r	   6   s      

8
8
:::r   TF)frozenreprc                  &    e Zd ZU dZded<   ded<   y)r   za
    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   F   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   r
   r   )r#   	raw_tokens     r   r
   r
   S   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/   c   s    499;Lr   r/   c                  8    e Zd ZdZddZddZ	 	 	 	 	 	 	 	 ddZy)	r   _var_value	_redeemedc                .    || _         || _        d| _        y )NFr4   )selfvarvalues      r   __init__zRunvarToken.__init__j   s    	=Br   c                    | S Nr   r9   s    r   	__enter__zRunvarToken.__enter__o   s    r   c                :    | j                   j                  |        y r>   )r5   reset)r9   exc_typeexc_valexc_tbs       r   __exit__zRunvarToken.__exit__r   s     			r   N)r:   z	RunVar[T]r;   %T | Literal[_NoValueSet.NO_VALUE_SET])returnRunvarToken[T])rC   ztype[BaseException] | NonerD   zBaseException | NonerE   zTracebackType | NonerH   None)r&   r'   r(   	__slots__r<   r@   rF   r   r   r   r   r   g   s<    -I
, & %	
 
r   r   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)r   a  
    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]r2   c                     || _         || _        y r>   rM   )r9   namedefaults      r   r<   zRunVar.__init__   s     
r   c                v    t               j                  }	 t        |   S # t        $ r i x}t        |<   |cY S w xY wr>   )r
   r%   r-   KeyError)r9   r%   run_varss      r   _current_varszRunVar._current_vars   sB    $33	\** 	133Hy.O	s    88c                     y r>   r   r9   rR   s     r   getz
RunVar.get   s    (+r   c                     y r>   r   r?   s    r   rY   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)rV   rT   r   r2   rO   LookupErrorrN   rX   s     r   rY   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 r>   )rV   r   rY   r   r2   )r9   r;   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)r5   
ValueErrorr7   r6   r/   r2   rV   rT   )r9   r_   s     r   rB   z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=>)rN   r?   s    r   __repr__zRunVar.__repr__   s    tzznA..r   N)rQ   strrR   rG   )rH   zdict[RunVar[T], T])rR   r   rH   T | D)rH   r   )rR   z%D | Literal[_NoValueSet.NO_VALUE_SET]rH   rg   )r;   r   rH   rI   )r_   rI   rH   rJ   )rH   rf   )r&   r'   r(   r)   rK   r/   r2   r*   r<   propertyrV   r   rY   r`   rB   re   r   r   r   r   r   {   s     $I6A6N6NL3N KW  "G    + +  @L
<
	
"/r   r   )rH   rJ   )rH   r   )"
__future__r   __all__r0   dataclassesr   typesr   typingr   r   r   r   r   r   weakrefr   _core._eventloopr   abcr   r   r   r   r   r	   r   r
   r-   r*   Enumr/   r   r   r   r   r   <module>rr      s    "  !  B B % / CLCL+ 	8;  
$U#  $ 
4 @Q?R	< R$)) '!* (H/WQZ H/r   