
    Jn6h+                     P    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y)    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y)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 | _
        y )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      `/var/www/django-portfolio.reubendavern.link/venv/lib/python3.12/site-packages/asgiref/timeout.py__init__ztimeout.__init__   sV      <++-DMMCEW 

#    c                 "    | j                         S N	_do_enterr   s    r   	__enter__ztimeout.__enter__2   s    ~~r   exc_typeexc_valexc_tbc                 &    | j                  |       y r   _do_exitr   r!   r"   r#   s       r   __exit__ztimeout.__exit__5   s     	hr   c                 *   K   | j                         S wr   r   r   s    r   
__aenter__ztimeout.__aenter__>   s     ~~s   c                 .   K   | j                  |       y wr   r%   r'   s       r   	__aexit__ztimeout.__aexit__A   s      	hs   c                     | j                   S r   )r   r   s    r   expiredztimeout.expiredI   s    r   c                 ~    | j                   1t        | j                   | j                  j                         z
  d      S y )Ng        )r   maxr   timer   s    r   	remainingztimeout.remainingM   s0    ??&t)::C@@r   c                    | j                   | S t        j                  | j                        | _        | j                  t        d      | j                   dk  r'| j                  j                  | j                         | S | j                  j                         | j                   z   | _	        | j                  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
::I  ==AJJ  !2!23K**//+dmm;#zz11$//4CTCTUr   c                     |t         j                  u r*| j                  rd | _        d | _        t         j
                  | j                  -| j                  !| j                  j                          d | _        d | _        y r   )r   CancelledErrorr   r   r   TimeoutErrorr   cancel)r   r!   s     r   r&   ztimeout._do_exith   sj    w---$//#'D DJ&&&==$)=)=)I  '')#'D 
r   c                 `    | j                   "| j                   j                          d| _        y y )NT)r   r<   r   r   s    r   r7   ztimeout._cancel_tasks   s(    ::!JJ"DO "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01	
 
& }%  	
 
$  }%    	 
 
     8E?  (	m!4 	 	#r   r   )	r   r   typesr   typingr   r   r   r   rG   r   r   <module>rJ      s"        !f# f#r   