
    d
                         d dl Z d dlmZ d dlmZmZmZ ddlmZ ddlm	Z	 ddlm
Z
 dZ G d	 d
e j                  Ze G d d                      Zdee         defdZdee         defdZdS )    N)TracebackType)finalOptionalType   )events)
exceptions)tasks)Timeouttimeout
timeout_atc                   "    e Zd ZdZdZdZdZdZdS )_StatecreatedactiveexpiringexpiredfinishedN)__name__
__module____qualname__CREATEDENTEREDEXPIRINGEXPIREDEXITED     "  /croot/python-split_1694437901252/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_plac/lib/python3.11/asyncio/timeouts.pyr   r      s'        GGHGFFFr   r   c            	           e Zd ZdZdee         ddfdZdee         fdZdee         ddfdZde	fdZ
defd	Zdd
Zdeee                  dee         dee         dee	         fdZddZdS )r   zAsynchronous context manager for cancelling overdue coroutines.

    Use `timeout()` or `timeout_at()` rather than instantiating this class directly.
    whenreturnNc                 R    t           j        | _        d| _        d| _        || _        dS )zSchedule a timeout that will trigger at a given loop time.

        - If `when` is `None`, the timeout will never trigger.
        - If `when < loop.time()`, the timeout will trigger on the next
          iteration of the event loop.
        N)r   r   _state_timeout_handler_task_when)selfr!   s     r   __init__zTimeout.__init__!   s'     n>B+/



r   c                     | j         S )zReturn the current deadline.)r'   r(   s    r   r!   zTimeout.when.   s
    zr   c                    | j         t          j        usJ | j         t          j        urt	          d| j         j         d          || _        | j        | j                                         |	d| _        dS t          j
                    }||                                k    r!|                    | j                  | _        dS |                    || j                  | _        dS )zReschedule the timeout.zCannot change state of z TimeoutN)r$   r   r   r   RuntimeErrorvaluer'   r%   cancelr   get_running_looptime	call_soon_on_timeoutcall_at)r(   r!   loops      r   
reschedulezTimeout.reschedule2   s    {&.0000;fn,,E$+*;EEE   
 ,!((***<$(D!!!*,,Dtyy{{""(,t7G(H(H%%%(,T4;K(L(L%%%r   c                 @    | j         t          j        t          j        fv S )z$Is timeout expired during execution?)r$   r   r   r   r+   s    r   r   zTimeout.expiredH   s    {v???r   c                     dg}| j         t          j        u r6| j        t	          | j        d          nd }|                    d|            d                    |          }d| j         j         d| dS )N    zwhen= z
<Timeout []>)r$   r   r   r'   roundappendjoinr.   )r(   infor!   info_strs       r   __repr__zTimeout.__repr__L   sz    t;&.((+/:+A5Q'''tDKK'''88D>>;DK-;;;;;;r   c                    K   t           j        | _        t          j                    | _        | j                                        | _        | j        t          d          | 	                    | j
                   | S )Nz$Timeout should be used inside a task)r   r   r$   r
   current_taskr&   
cancelling_cancellingr-   r6   r'   r+   s    r   
__aenter__zTimeout.__aenter__T   se      n'))
:0022:EFFF
###r   exc_typeexc_valexc_tbc                   K   | j         t          j        t          j        fv sJ | j         | j                                         d | _        | j         t          j        u rJt          j        | _         | j                                        | j	        k    r|t          j        u rt          |n$| j         t          j        u rt          j        | _         d S N)r$   r   r   r   r%   r/   r   r&   uncancelrG   r	   CancelledErrorTimeoutErrorr   )r(   rI   rJ   rK   s       r   	__aexit__zTimeout.__aexit__]   s       {v~v????? ,!((***$(D!;&/)) .DKz""$$(888XIb=b=b #/[FN** -DKtr   c                     | j         t          j        u sJ | j                                         t          j        | _         d | _        d S rM   )r$   r   r   r&   r/   r   r%   r+   s    r   r3   zTimeout._on_timeoutu   sB    {fn,,,,
o $r   )r"   r   )r"   N)r   r   r   __doc__r   floatr)   r!   r6   boolr   strrC   rH   r   BaseExceptionr   rQ   r3   r   r   r   r   r      sD        
Xe_     huo    Mx M4 M M M M,@ @ @ @ @<# < < < <   4./ -( '	
 
$   0% % % % % %r   r   delayr"   c                 x    t          j                    }t          | |                                | z   nd          S )a	  Timeout async context manager.

    Useful in cases when you want to apply timeout logic around block
    of code or in cases when asyncio.wait_for is not suitable. For example:

    >>> async with asyncio.timeout(10):  # 10 seconds timeout
    ...     await long_running_task()


    delay - value in seconds or None to disable timeout logic

    long_running_task() is interrupted by raising asyncio.CancelledError,
    the top-most affected timeout() context manager converts CancelledError
    into TimeoutError.
    N)r   r0   r   r1   )rX   r5   s     r   r   r   }   s7      "$$D%*;499;;&&FFFr   r!   c                      t          |           S )ab  Schedule the timeout at absolute time.

    Like timeout() but argument gives absolute time in the same clock system
    as loop.time().

    Please note: it is not POSIX time but a time with
    undefined starting base, e.g. the time of the system power on.

    >>> async with asyncio.timeout_at(loop.time() + 10):
    ...     await long_running_task()


    when - a deadline when timeout occurs or None to disable timeout logic

    long_running_task() is interrupted by raising asyncio.CancelledError,
    the top-most affected timeout() context manager converts CancelledError
    into TimeoutError.
    )r   )r!   s    r   r   r      s    & 4==r   )enumtypesr   typingr   r   r   r9   r   r	   r
   __all__Enumr   r   rT   r   r   r   r   r   <module>r`      s@          ( ( ( ( ( ( ( ( ( (                      TY    _% _% _% _% _% _% _% _%DG8E? Gw G G G G(Xe_       r   