NfddlZddlmZddlmZmZmZddlmZddlm Z ddlm Z dZ Gd d ej Z eGd d Zd eedefdZdeedefdZdS)N) TracebackType)finalOptionalType)events) exceptions)tasks)Timeouttimeout timeout_atc"eZdZdZdZdZdZdZdS)_StatecreatedactiveexpiringexpiredfinishedN)__name__ __module__ __qualname__CREATEDENTEREDEXPIRINGEXPIREDEXITED'/usr/lib/python3.11/asyncio/timeouts.pyrrs'GGHG FFFrrc eZdZdeeddfdZdeefdZdeeddfdZdefdZ de fdZ dd Z d ee ed eed eedeefd ZddZdS)r whenreturnNcRtj|_d|_d|_||_dSN)rr_state_timeout_handler_task_when)selfr!s r__init__zTimeout.__init__s%n >B+/  rc|jSr$)r(r)s rr!z Timeout.when$s zrc|jtjusJ|jtjurt d|jjd||_|j|j| d|_dStj }|| kr!| |j |_dS|||j |_dS)NzCannot change state of z Timeout)r%rrr RuntimeErrorvaluer(r&cancelrget_running_looptime call_soon _on_timeoutcall_at)r)r!loops r reschedulezTimeout.reschedule's{&.0000 ;fn , ,E$+*;EEE   ,  ! ( ( * * * <$(D ! ! !*,,Dtyy{{""(,t7G(H(H%%%(, T4;K(L(L%%%rc@|jtjtjfvS)z$Is timeout expired during execution?)r%rrrr,s rrzTimeout.expired<s{v???rcdg}|jtjur6|jt |jdnd}|d|d|}d|jjd|dS)Nzwhen= z )r%rrr(roundappendjoinr/)r)infor!info_strs r__repr__zTimeout.__repr__@szt ;&. ( (+/:+A5Q'''tD KK ' ' '88D>>;DK-;;;;;;rcKtj|_tj|_|jt d||j|S)Nz$Timeout should be used inside a task) rrr%r current_taskr'r.r7r(r,s r __aenter__zTimeout.__aenter__HsOn ')) : EFF F  ### rexc_typeexc_valexc_tbcK|jtjtjfvsJ|j |jd|_|jtjurDtj|_|jdkr|tj urtn$|jtjurtj |_dS)Nr) r%rrrr&r0rr'uncancelr CancelledError TimeoutErrorr)r)rHrIrJs r __aexit__zTimeout.__aexit__Ps {v~v?????  ,  ! ( ( * * *$(D ! ;&/ ) ) .DKz""$$))h*:S.S.S#" [FN * * -DKtrc|jtjusJ|jtj|_d|_dSr$)r%rrr'r0rr&r,s rr4zTimeout._on_timeouthsB{fn,,,, o $r)r"r )r"N)rrrrfloatr*r!r7boolrstrrDrGr BaseExceptionrrOr4rrrr r s:Xe_huoMxM4MMMM*@@@@@<#<<<<4 ./-('  $ 0%%%%%%rr delayr"cxtj}t|||zndS)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)rr1r r2)rUr6s rr r ps7  " $ $D %*;499;;&& F FFrr!c t|S)abSchedule 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 rr r s& 4==r)enumtypesrtypingrrrr:rr r __all__Enumrr rQr r rrrr]s@ (((((((((( TYR%R%R%R%R%R%R%R%jG8E?GwGGGG(Xe_r