o 6ap @s:ddlZddlmZddlmZmZmZGdddZdS)N) TracebackType)AnyOptionalTypec @seZdZdZdddeedeejddfddZddd Z d e e d e d e dee fd dZdddZd e e d e d e ddfddZede fddZedeefddZdddZd e e ddfddZdddZdS)timeoutatimeout 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: >>> with timeout(0.001): ... async with aiohttp.get('https://github.com') as r: ... await r.text() timeout - value in seconds or None to disable timeout logic loop - asyncio compatible event loop N)looprreturncCs8||_|dur t}||_d|_d|_d|_d|_dS)NF)_timeoutasyncioget_event_loop_loop_task _cancelled_cancel_handler _cancel_at)selfrrr1/usr/lib/python3/dist-packages/asgiref/timeout.py__init__s ztimeout.__init__cCs|SN _do_enterrrrr __enter__,sztimeout.__enter__exc_typeexc_valexc_tbcCs||dSr_do_exitrrrrrrr__exit__/s ztimeout.__exit__cs |Srrrrrr __aenter__8sztimeout.__aenter__cs||dSrrrrrr __aexit__;sztimeout.__aexit__cCs|jSr)rrrrrexpiredCsztimeout.expiredcCs$|jdurt|j|jdSdS)Ng)rmaxr timerrrr remainingGs ztimeout.remainingcCst|jdur|St|j|_|jdurtd|jdkr%|j|j|S|j|j|_ |j |j |j|_ |S)Nz4Timeout context manager should be used inside a taskr) r r current_taskr r RuntimeError call_soon _cancel_taskr%rcall_atrrrrrrNs   ztimeout._do_entercCsP|tjur|jrd|_d|_tj|jdur#|jdur#|jd|_d|_dSr)r CancelledErrorrrr TimeoutErrorr cancel)rrrrrrbs ztimeout._do_exitcCs"|jdur|jd|_dSdS)NT)r r.rrrrrr*ms   ztimeout._cancel_task)rr)rN)__name__ __module__ __qualname____doc__rfloatr AbstractEventLooprrr BaseExceptionrboolr r!r"propertyr#r&rrr*rrrrrsJ     r)r typesrtypingrrrrrrrrs