
    FZj                    t   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mZ d dlmZ dd	lmZ e	r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)TYPE_CHECKING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        PC:\Users\Rodrigo\frota-trucks-cliente\python\Lib\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	   7   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.

    :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                  .    e Zd Z ej                         Zy)_NoValueSetN)r'   r(   r)   enumautoNO_VALUE_SETr   r   r   r0   r0   f   s    499;Lr   r0   c                  <    e Zd ZdZdZddZddZ	 	 	 	 	 	 	 	 d	dZy)
r   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                .    || _         || _        d| _        y )NFr5   )selfvarvalues      r   __init__zRunvarToken.__init__t   s    	=Br   c                    | S Nr   r:   s    r   	__enter__zRunvarToken.__enter__y   s    r   c                :    | j                   j                  |        y r?   )r6   reset)r:   exc_typeexc_valexc_tbs       r   __exit__zRunvarToken.__exit__|   s     			r   N)r;   z	RunVar[T]r<   %T | Literal[_NoValueSet.NO_VALUE_SET])returnRunvarToken[T])rD   ztype[BaseException] | NonerE   zBaseException | NonerF   zTracebackType | NonerI   None)r'   r(   r)   r*   	__slots__r=   rA   rG   r   r   r   r   r   j   sC     .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]r3   c                     || _         || _        y r?   rN   )r:   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)r:   r&   run_varss      r   _current_varszRunVar._current_vars   sB    $33	\** 	133Hy.O	s    88c                     y r?   r   r:   rS   s     r   getz
RunVar.get   s    (+r   c                     y r?   r   r@   s    r   rZ   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      )a2  
        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)rW   rU   r   r3   rP   LookupErrorrO   rY   s     r   rZ   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 )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

        )rW   r   rZ   r   r3   )r:   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)a  
        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)r6   
ValueErrorr8   r7   r0   r3   rW   rU   )r:   r`   s     r   rC   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=>)rO   r@   s    r   __repr__zRunVar.__repr__   s    tzznA..r   N)rR   strrS   rH   )rI   zdict[RunVar[T], T])rS   r   rI   T | D)rI   r   )rS   z%D | Literal[_NoValueSet.NO_VALUE_SET]rI   rh   )r<   r   rI   rJ   )r`   rJ   rI   rK   )rI   rg   )r'   r(   r)   r*   rL   r0   r3   r+   r=   propertyrW   r   rZ   ra   rC   rf   r   r   r   r   r      s     $I6A6N6NL3N KW  "G    + +  @L
<
	
.2/r   r   )rI   rK   )rI   r   )#
__future__r   __all__r1   dataclassesr   typesr   typingr   r   r   r   r   r   r   weakrefr   _core._eventloopr   abcr   r   r   r   r   r	   r   r
   r.   r+   Enumr0   r   r   r   r   r   <module>rs      s    "  !  Q Q Q % /!CLCL+	8; 
$U#  $ 4  @Q?R	< R$)) '!* 6_/WQZ _/r   