Format: application/x-python-code
⬇ Download File (3.2 KB)
   1  o
   2  
   3  -h+�@sJddlZddlZddlmZddlmZddlmZmZGdd�d�ZdS)�N)�
   4  TracebackType)�Any)�Optional�Typec	@s�eZdZdZdd�deedeejddfdd�Zddd	�Z	d
   5  e
   6  edededee
   7  fd
   8  d�Zddd�Zd
   9  e
  10  edededdfdd�Zede
  11  fdd��Zedeefdd��Zddd�Zd
  12  e
  13  eddfdd�Zddd�ZdS)�timeouta�timeout context manager.
  14  
  15      Useful in cases when you want to apply timeout logic around block
  16      of code or in cases when asyncio.wait_for is not suitable. For example:
  17  
  18      >>> with timeout(0.001):
  19      ...     async with aiohttp.get('https://github.com') as r:
  20      ...         await r.text()
  21  
  22  
  23      timeout - value in seconds or None to disable timeout logic
  24      loop - asyncio compatible event loop
  25      N)�loopr�returncCsF||_|durt��}nt�dt�||_d|_d|_d|_	d|_
  26  dS)Nz-The loop argument to timeout() is deprecated.F)�_timeout�asyncio�get_running_loop�warnings�warn�DeprecationWarning�_loop�_task�
  27  _cancelled�_cancel_handler�
  28  _cancel_at)�selfrr�r�EC:\Users\shubh\Videos\agent\nova\Lib\site-packages\asgiref/timeout.py�__init__s
  29  �
  30  ztimeout.__init__cCs|��S�N��	_do_enter�rrrr�	__enter__2sztimeout.__enter__�exc_type�exc_val�exc_tbcCs|�|�dSr��_do_exit�rrrrrrr�__exit__5s
  31  ztimeout.__exit__c�s
  32  �|��Srrrrrr�
  33  __aenter__>s�ztimeout.__aenter__c�s�|�|�dSrr r"rrr�	__aexit__As�ztimeout.__aexit__cCs|jSr)rrrrr�expiredIsztimeout.expiredcCs$|jdurt|j|j��d�SdS)Ng)r�maxr�timerrrr�	remainingMs
  34  ztimeout.remainingcCst|jdur|St�|j�|_|jdurtd��|jdkr%|j�|j�|S|j��|j|_	|j�
  35  |j	|j�|_|S)Nz4Timeout context manager should be used inside a taskr)r	r
  36  �current_taskrr�RuntimeError�	call_soon�_cancel_taskr(r�call_atrrrrrrTs
  37  
  38  �
  39  ztimeout._do_entercCsP|tjur|jrd|_d|_tj�|jdur#|jdur#|j��d|_d|_dSr)r
  40  �CancelledErrorrrr�TimeoutErrorr	�cancel)rrrrrr!hs
  41  ztimeout._do_exitcCs"|jdur|j��d|_dSdS)NT)rr1rrrrrr-ss
  42  
  43  
  44  �ztimeout._cancel_task)rr)rN)�__name__�
  45  __module__�__qualname__�__doc__r�floatr
  46  �AbstractEventLooprrr�
  47  BaseExceptionr�boolr#r$r%�propertyr&r)rr!r-rrrrrsJ���
  48  �
  49  ���
  50  �
  51  	���
  52  �
  53  r)	r
  54  r�typesr�typingrrrrrrrr�<module>s