
    i                        d dl mZ d dlZd dlmZmZmZ d dlmZ dZ	 G d dej
                  Z G d d	          ZddZdS )    )annotationsN)CancelledErroreventstasks)TracebackType)Timeouttimeoutc                  "    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     ^/root/projects/butler/venv/lib/python3.11/site-packages/urllib3_future/contrib/ssa/_timeout.pyr   r      s'        GGHGFFFr   r   c                  R    e Zd ZdZddZddZddZdd
ZddZddZ	d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float | NonereturnNonec                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KO(,



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r?| j         t          j        u rt	          d          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Timeout has not been enteredz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.reschedule,   s    ;fn,,{fn,,"#ABBBE$+*;EEE   
 ,!((***<$(D!!!*,,Dtyy{{""(,t7G(H(H%%%(,T4;K(L(L%%%r   boolc                @    | j         t          j        t          j        fv S )z$Is timeout expired during execution?)r"   r   r   r   r)   s    r   r   zTimeout.expiredC   s    {v???r   strc                    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__G   sz    t;&.((+/:+A5Q'''tDKK'''88D>>;DK-;;;;;;r   	'Timeout'c                   K   | j         t          j        urt          d          t	          j                    }|t          d          t          j        | _         || _        |                     | j	                   | S )Nz Timeout has already been enteredz$Timeout should be used inside a task)
r"   r   r   r+   r   current_taskr   r$   r4   r%   )r&   tasks     r   
__aenter__zTimeout.__aenter__O   so      ;fn,,ABBB!##<EFFFn

###r   exc_typetype[BaseException] | Noneexc_valBaseException | Noneexc_tbTracebackType | Nonec                `  K   | j         t          j        t          j        fv sJ | j        J | j         | j                                         d | _        | j         t          j        u r#t          j        | _         |t          u rt          |n$| j         t          j        u rt          j
        | _         d S N)r"   r   r   r   r$   r#   r-   r   r   TimeoutErrorr   )r&   rI   rK   rM   s       r   	__aexit__zTimeout.__aexit__Z   s       {v~v?????z%%% ,!((***$(D!;&/)) .DK>)) #/ * [FN** -DKtr   c                    | j         t          j        u sJ | j        J | j                                         t          j        | _         d | _        d S rP   )r"   r   r   r$   r-   r   r#   r)   s    r   r1   zTimeout._on_timeouts   sP    {fn,,,,z%%%
o $r   N)r   r   r   r    )r   r   )r   r5   )r   r7   )r   rD   )rI   rJ   rK   rL   rM   rN   r   r    )r   r    )r   r   r   __doc__r'   r   r4   r   rC   rH   rR   r1   r   r   r   r   r      s         
      M M M M.@ @ @ @< < < <	 	 	 	   2% % % % % %r   r   delayr   r   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   r.   r   r/   )rU   r3   s     r   r	   r	   }   s7      "$$D%*;499;;&&FFFr   )rU   r   r   r   )
__future__r   enumasyncior   r   r   typesr   __all__Enumr   r   r	   r   r   r   <module>r]      s    " " " " " "  1 1 1 1 1 1 1 1 1 1          TY   e% e% e% e% e% e% e% e%PG G G G G Gr   