
    _j                       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"dS )"    )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DreturnNonec                 V   K   t                                                       d{V  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   r        B/home/drrone/.local/lib/python3.11/site-packages/anyio/lowlevel.pyr   r      s8       


(
(
*
**********r   c                 V   K   t                                                       d{V  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   r   r   r   r   r   r   +   s8       


5
5
7
7777777777r   c                 V   K   t                                                       d{V  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   r	   r   r   r   r	   r	   7   s8       


8
8
:
::::::::::r   TF)frozenreprc                  (    e Zd ZU dZded<   ded<   dS )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   s6           &%%%r   r   c                 f    t                      } |                                 }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   s0     &''M++--I-333r   z1WeakKeyDictionary[object, dict[RunVar[Any], Any]]	_run_varsc                  ,    e Zd Z ej                    ZdS )_NoValueSetN)r(   r)   r*   enumautoNO_VALUE_SETr   r   r   r1   r1   f   s        49;;LLLr   r1   c                  .    e Zd ZdZdZddZdd
ZddZdS )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	_redeemedvar	RunVar[T]value%T | Literal[_NoValueSet.NO_VALUE_SET]c                0    || _         || _        d| _        d S )NFr6   )selfr:   r<   s      r   __init__zRunvarToken.__init__t   s    	=Br   r   RunvarToken[T]c                    | S Nr   r?   s    r   	__enter__zRunvarToken.__enter__y   s    r   exc_typetype[BaseException] | Noneexc_valBaseException | Noneexc_tbTracebackType | Noner   c                :    | j                             |            d S rC   )r7   reset)r?   rF   rH   rJ   s       r   __exit__zRunvarToken.__exit__|   s     		r   N)r:   r;   r<   r=   )r   rA   )rF   rG   rH   rI   rJ   rK   r   r   )r(   r)   r*   r+   	__slots__r@   rE   rN   r   r   r   r   r   j   sa          .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dS )$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]r4   namestrdefaultr=   c                "    || _         || _        d S rC   rQ   )r?   rT   rV   s      r   r@   zRunVar.__init__   s     
r   r   dict[RunVar[T], T]c                    t                      j        }	 t          |         S # t          $ r i x}t          |<   |cY S w xY wrC   )r
   r'   r/   KeyError)r?   r'   run_varss      r   _current_varszRunVar._current_vars   sQ    $3	\** 	 	 	133Hy.OOO	s   " ==r   T | Dc                    d S rC   r   r?   rV   s     r   getz
RunVar.get   s    (+r   r   c                    d S rC   r   rD   s    r   r`   z
RunVar.get   s    r   %D | Literal[_NoValueSet.NO_VALUE_SET]c                    	 | j         |          S # t          $ r1 |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)r\   rZ   r   r4   rS   LookupErrorrR   r_   s     r   r`   z
RunVar.get   s    	%%d++ 	% 	% 	%f111f&999}$$$ :9	% JTZJJJ
 
 	
s    A
A
	A
r<   rA   c                z    | j         }t          | |                    | 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

        )r\   r   r`   r   r4   )r?   r<   current_varstokens       r   setz
RunVar.set   s=     )D,"2"249L"M"MNN"Tr   rg   r   c                    |j         | urt          d          |j        rt          d          |j        t          j        u r	 | j        | = n# t          $ r Y nw xY w|j        | j        | <   d|_        dS )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)r7   
ValueErrorr9   r8   r1   r4   r\   rZ   )r?   rg   s     r   rM   zRunVar.reset   s     :T!!HIII? 	A?@@@<;333&t,,    (-|Dt$s   A 
AAc                    d| j         dS )Nz<RunVar name=>)rR   rD   s    r   __repr__zRunVar.__repr__   s    .tz....r   N)rT   rU   rV   r=   )r   rX   )rV   r   r   r]   )r   r   )rV   rb   r   r]   )r<   r   r   rA   )rg   rA   r   r   )r   rU   )r(   r)   r*   r+   rO   r1   r4   r,   r@   propertyr\   r   r`   rh   rM   rm   r   r   r   r   r      s          $I6A6NLNNNN KW             X +++ X+ X @L
 
 
 
 
.      2/ / / / / /r   r   )r   r   )r   r   )#
__future__r   __all__r2   dataclassesr   typesr   typingr   r   r   r   r   r   r   weakrefr   _core._eventloopr   abcr   r   r   r   r   r	   r   r
   r/   r,   Enumr1   r   r   r   r   r   <module>rx      s6   " " " " " " "  ! ! ! ! ! !       Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q % % % % % % / / / / / / "!!!!!!GCLLGCLL+ + + +	8 	8 	8 	8; ; ; ; 
$U###       $# 4 4 4 4  @Q?P?R?R	 R R R R    $)       '!*   6_/ _/ _/ _/ _/WQZ _/ _/ _/ _/ _/r   