o
    ýÞh+  ã                   @   sJ   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„ dƒZdS )é    N)ÚTracebackType)ÚAny)ÚOptionalÚTypec                	   @   sÜ   e Zd ZdZddœd ee deej ddfdd„Zddd	„Z	d
e
e dededee fdd„Zddd„Zd
e
e dededdfdd„Zedefdd„ƒZedee fdd„ƒZddd„Zd
e
e ddfdd„Zd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                C   sF   || _ |d u rt ¡ }nt 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   © r   úO/var/www/html/premium_crap/venv/lib/python3.10/site-packages/asgiref/timeout.pyÚ__init__   s   
ÿ
ztimeout.__init__c                 C   s   |   ¡ S ©N©Ú	_do_enter©r   r   r   r   Ú	__enter__2   s   ztimeout.__enter__Úexc_typeÚexc_valÚexc_tbc                 C   s   |   |¡ d S r   ©Ú_do_exit©r   r   r   r   r   r   r   Ú__exit__5   s   
ztimeout.__exit__c                 Ã   s
   �|   ¡ S r   r   r   r   r   r   Ú
__aenter__>   s   €ztimeout.__aenter__c                 Ã   s   �|   |¡ d S r   r    r"   r   r   r   Ú	__aexit__A   s   €ztimeout.__aexit__c                 C   s   | j S r   )r   r   r   r   r   ÚexpiredI   s   ztimeout.expiredc                 C   s$   | j d urt| j | j ¡  dƒS d S )Ng        )r   Úmaxr   Útimer   r   r   r   Ú	remainingM   s   
ztimeout.remainingc                 C   st   | j d u r| S t | j¡| _| jd u rtdƒ‚| j dkr%| 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(   r   Úcall_atr   r   r   r   r   r   T   s   

ÿ
ztimeout._do_enterc                 C   sP   |t ju r| jrd | _d | _t j‚| jd ur#| jd ur#| j ¡  d | _d | _d S r   )r
   ÚCancelledErrorr   r   r   ÚTimeoutErrorr	   Úcancel)r   r   r   r   r   r!   h   s   
ztimeout._do_exitc                 C   s"   | j d ur| j  ¡  d| _d S d S )NT)r   r1   r   r   r   r   r   r-   s   s   


þztimeout._cancel_task)r   r   )r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úfloatr
   ÚAbstractEventLoopr   r   r   ÚBaseExceptionr   Úboolr#   r$   r%   Úpropertyr&   r)   r   r!   r-   r   r   r   r   r      sJ    üþü
û
þýü
û
	þýü
û
r   )	r
   r   Útypesr   Útypingr   r   r   r   r   r   r   r   Ú<module>   s   