
    h                         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     '/usr/lib/python3.11/asyncio/timeouts.pyr   r      s'        GGHGFFFr   r   c            	           e 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   whenreturnNc                 R    t           j        | _        d | _        d | _        || _        d S N)r   r   _state_timeout_handler_task_when)selfr!   s     r   __init__zTimeout.__init__   s%    n>B+/



r   c                     | j         S r$   )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 )NzCannot change state of z Timeout)r%   r   r   r   RuntimeErrorvaluer(   r&   cancelr   get_running_looptime	call_soon_on_timeoutcall_at)r)   r!   loops      r   
reschedulezTimeout.reschedule'   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.expired<   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__@   sz    t;&.((+/:+A5Q'''tDKK'''88D>>;DK-;;;;;;r   c                    K   t           j        | _        t          j                    | _        | j        t          d          |                     | j                   | S )Nz$Timeout should be used inside a task)	r   r   r%   r
   current_taskr'   r.   r7   r(   r,   s    r   
__aenter__zTimeout.__aenter__H   sO      n'))
: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 rDt          j        | _         | j                                        dk    r|t          j
        u rt          n$| j         t          j        u rt          j        | _         d S )Nr   )r%   r   r   r   r&   r0   r   r'   uncancelr	   CancelledErrorTimeoutErrorr   )r)   rH   rI   rJ   s       r   	__aexit__zTimeout.__aexit__P   s       {v~v????? ,!((***$(D!;&/)) .DKz""$$))h*:S.S.S #"[FN** -DKtr   c                     | j         t          j        u sJ | j                                         t          j        | _         d | _        d S r$   )r%   r   r   r'   r0   r   r&   r,   s    r   r4   zTimeout._on_timeouth   sB    {fn,,,,
o $r   )r"   r   )r"   N)r   r   r   r   floatr*   r!   r7   boolr   strrD   rG   r   BaseExceptionr   rO   r4   r   r   r   r   r      s:       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   r1   r   r2   )rU   r6   s     r   r   r   p   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   r:   r   r	   r
   __all__Enumr   r   rQ   r   r   r   r   r   <module>r]      s@          ( ( ( ( ( ( ( ( ( (                      TY    R% R% R% R% R% R% R% R%jG8E? Gw G G G G(Xe_       r   