
    F\h                         S SK r S SKJr  S SKJrJrJr  SSKJr  SSKJ	r	  SSKJ
r
  Sr " S	 S
\ R                  5      r\ " S S5      5       rS\\   S\4S jrS\\   S\4S jrg)    N)TracebackType)finalOptionalType   )events)
exceptions)tasks)Timeouttimeout
timeout_atc                   (    \ rS rSrSrSrSrSrSrSr	g)	_State   createdactiveexpiringexpiredfinished N)
__name__
__module____qualname____firstlineno__CREATEDENTEREDEXPIRINGEXPIREDEXITED__static_attributes__r       '/usr/lib/python3.13/asyncio/timeouts.pyr   r      s    GGHGFr!   r   c            	           \ rS rSrSrS\\   SS4S jrS\\   4S jrS\\   SS4S jr	S\
4S	 jrS\4S
 jrSS jrS\\\      S\\   S\\   S\\
   4S jrSS jr\S\SS4S j5       rSrg)r      zAsynchronous context manager for cancelling overdue coroutines.

Use `timeout()` or `timeout_at()` rather than instantiating this class directly.
whenreturnNc                 V    [         R                  U l        SU l        SU l        Xl        g)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__Timeout.__init__!   s#     nn>B+/

r!   c                     U R                   $ )zReturn the current deadline.)r+   r,   s    r"   r%   Timeout.when.   s    zzr!   c                    U R                   [        R                  LaK  U R                   [        R                  L a  [	        S5      e[	        SU R                   R
                   S35      eXl        U R                  b  U R                  R                  5         Uc  SU l        g[        R                  " 5       nXR                  5       ::  a!  UR                  U R                  5      U l        gUR                  XR                  5      U l        g)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"   
rescheduleTimeout.reschedule2   s    ;;fnn,{{fnn,"#ABB)$++*;*;)<HE  
  ,!!((*<$(D!**,Dyy{"(,t7G7G(H%(,T;K;K(L%r!   c                 \    U R                   [        R                  [        R                  4;   $ )z$Is timeout expired during execution?)r(   r   r   r   r0   s    r"   r   Timeout.expiredI   s    {{v???r!   c                    S/nU R                   [        R                  L a9  U R                  b  [	        U R                  S5      OS nUR                  SU 35        SR                  U5      nSU R                   R                   SU S3$ )N    zwhen= z
<Timeout []>)r(   r   r   r+   roundappendjoinr4   )r,   infor%   info_strs       r"   __repr__Timeout.__repr__M   ss    t;;&..(+/::+A5Q'tDKK%v'88D>DKK--.az;;r!   c                 N  #    U R                   [        R                  La  [        S5      e[        R
                  " 5       nUc  [        S5      e[        R                  U l         Xl        U R                  R                  5       U l	        U R                  U R                  5        U $ 7f)Nz Timeout has already been enteredz$Timeout should be used inside a task)r(   r   r   r3   r
   current_taskr   r*   
cancelling_cancellingr<   r+   )r,   tasks     r"   
__aenter__Timeout.__aenter__U   sz     ;;fnn,ABB!!#<EFFnn
::002

#s   B#B%exc_typeexc_valexc_tbc                   #    U R                   [        R                  [        R                  4;   d   eU R                  b!  U R                  R                  5         S U l        U R                   [        R                  L a  [        R                  U l         U R                  R                  5       U R                  ::  av  Ubs  [        U[        R                  5      (       a  [        UeUbJ  U R                  U5        [        U[         5      (       a$  UR                   H  nU R                  U5        M     g U R                   [        R                  L a  [        R"                  U l         g 7fN)r(   r   r   r   r)   r5   r   r*   uncancelrP   
issubclassr	   CancelledErrorTimeoutError_insert_timeout_error
isinstanceExceptionGroupr   )r,   rT   rU   rV   excs        r"   	__aexit__Timeout.__aexit__a   s     {{v~~v????  ,!!((*$(D!;;&//) ..DKzz""$(8(88X=Q h
(A(ABB&G3(..w7!'>::#*#5#5C 66s; $6
  [[FNN* --DKs   E#E%c                     U R                   [        R                  L d   eU R                  R	                  5         [        R
                  U l         S U l        g rX   )r(   r   r   r*   r5   r   r)   r0   s    r"   r9   Timeout._on_timeout   s;    {{fnn,,,

oo $r!   c                     U R                   bn  [        U R                   [        R                  5      (       a)  [	        5       nU R                   =Ul         Ul        Xl         g U R                   n U R                   b  Mm  g g rX   )__context__r^   r	   r[   r\   	__cause__)rU   tes     r"   r]   Timeout._insert_timeout_error   sd    !!-'--z/H/HII!^070C0CC&(#))G !!-r!   )rP   r(   r*   r)   r+   )r&   r   )r&   N)r   r   r   r   __doc__r   floatr-   r%   r<   boolr   strrK   rR   r   BaseExceptionr   ra   r9   staticmethodr]   r    r   r!   r"   r   r      s    
Xe_  huo Mx M4 M.@ @<# <
4./ -( '	
 
$<% *} * * *r!   r   delayr&   c                 v    [         R                  " 5       n[        U b  UR                  5       U -   5      $ S5      $ )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   r6   r   r7   )rp   r;   s     r"   r   r      s5      ""$D%*;499;&FFFFr!   r%   c                     [        U 5      $ )a6  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   rA   r   r	   r
   __all__Enumr   r   rk   r   r   r   r!   r"   <module>rx      s      ( (   TYY  s* s* s*lG8E? Gw G(Xe_  r!   