
    _f+                     X    d dl Z d dlZd dlmZ d dlmZ d dlmZmZ  G d d          ZdS )    N)TracebackType)Any)OptionalTypec            	       "   e Zd ZdZddd ee         deej                 ddfdZddZ	de
e         d	ed
edee         fdZddZde
e         d	ed
eddfdZedefd            Zedee         fd            ZddZde
e         ddfdZddZdS )timeouta  timeout 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)loopr	   returnc                    || _         |t          j                    }nt          j        dt
                     || _        d | _        d| _        d | _	        d | _
        d S )Nz-The loop argument to timeout() is deprecated.F)_timeoutasyncioget_running_loopwarningswarnDeprecationWarning_loop_task
_cancelled_cancel_handler
_cancel_at)selfr   r	   s      A/var/www/html/env/lib/python3.11/site-packages/asgiref/timeout.py__init__ztimeout.__init__   sd      <+--DDMCEW   

#    c                 *    |                                  S N	_do_enterr   s    r   	__enter__ztimeout.__enter__2   s    ~~r   exc_typeexc_valexc_tbc                 0    |                      |           d S r   _do_exitr   r!   r"   r#   s       r   __exit__ztimeout.__exit__5   s     	htr   c                 .   K   |                                  S r   r   r   s    r   
__aenter__ztimeout.__aenter__>   s      ~~r   c                 4   K   |                      |           d S r   r%   r'   s       r   	__aexit__ztimeout.__aexit__A   s        	hr   c                     | j         S r   )r   r   s    r   expiredztimeout.expiredI   s
    r   c                 r    | j         /t          | j         | j                                        z
  d          S d S )Ng        )r   maxr   timer   s    r   	remainingztimeout.remainingM   s2    ?&t):)::C@@@4r   c                 x   | j         | S t          j        | j                  | _        | j        t          d          | j         dk    r!| j                            | j                   | S | j                                        | j         z   | _	        | j        
                    | j	        | j                  | _        | S )Nz4Timeout context manager should be used inside a taskr   )r   r   current_taskr   r   RuntimeError	call_soon_cancel_taskr1   r   call_atr   r   s    r   r   ztimeout._do_enterT   s     = K)$*55
:I   =AJ  !2333K*//++dm;#z11$/4CTUUr   c                     |t           j        u r!| j        rd | _        d | _        t           j        | j        '| j         | j                                         d | _        d | _        d S r   )r   CancelledErrorr   r   r   TimeoutErrorr   cancel)r   r!   s     r   r&   ztimeout._do_exith   sh    w---$/-#'D DJ&&=$)=)I '')))#'D 
tr   c                 X    | j         "| j                                          d| _        d S d S )NT)r   r<   r   r   s    r   r7   ztimeout._cancel_tasks   s1    :!J"DOOO "!r   )r
   r   )r
   N)__name__
__module____qualname____doc__r   floatr   AbstractEventLoopr   r    r   BaseExceptionr   boolr(   r*   r,   propertyr.   r2   r   r&   r7    r   r   r   r      s        $ 59	  % w01	
 
   &       }%  	
 
$           }%    	 
 
            X 8E?    X   (	m!4 	 	 	 	 	# # # # # #r   r   )	r   r   typesr   typingr   r   r   r   rG   r   r   <module>rJ      s                  ! ! ! ! ! ! ! !f# f# f# f# f# f# f# f# f# f#r   