o
    GgJ                     @   s   d dl Z d dlZd dlZd dlZd dlmZ d dlmZmZ ej	dkr*d dlm
Z
 nd dlm
Z
 ej	dkr;dd
dZndddZdZdZdee d	dfddZdee d	dfddZG dd dejZe
G dd dZdS )    N)TracebackType)OptionalType)      )final)r      taskasyncio.Task[object]returnc                 C   s   |    d S N)uncancelr	    r   Y/var/www/html/AyurvedaChatbot/venv/lib/python3.10/site-packages/async_timeout/__init__.py_uncancel_task   s   r   c                 C   s   d S r   r   r   r   r   r   r      s   z4.0.3)timeout
timeout_atTimeoutdelayr   c                 C   s,   t  }| dur| |  }nd}t||S )ar  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:

    >>> async with timeout(0.001):
    ...     async with aiohttp.get('https://github.com') as r:
    ...         await r.text()


    delay - value in seconds or None to disable timeout logic
    N)asyncioget_running_looptimer   )r   loopdeadliner   r   r   r       s
   
r   r   c                 C   s   t  }t| |S )a  Schedule the timeout at absolute time.

    deadline argument points on the time in the same clock system
    as loop.time().

    Please note: it is not POSIX time but a time with
    undefined starting base, e.g. the time of the system power on.

    >>> async with timeout_at(loop.time() + 10):
    ...     async with aiohttp.get('https://github.com') as r:
    ...         await r.text()


    )r   r   r   )r   r   r   r   r   r   5   s   
r   c                   @   s   e Zd ZdZdZdZdZdS )_StateINITENTERTIMEOUTEXITN)__name__
__module____qualname__r   r   r   r   r   r   r   r   r   H   s
    r   c                	   @   s4  e Zd ZdZdee dejddfddZd(dd	Z	d
ee
e  dee dee dee fddZd(ddZd
ee
e  dee dee dee fddZedefddZedee fddZd)ddZd)ddZdeddfddZdeddfddZd)d d!Zd)d"d#Zd
ee
e  ddfd$d%Zd)d&d'ZdS )*r   )	_deadline_loop_state_timeout_handler_taskr   r   r   Nc                 C   s:   || _ tj| _d | _d | _|d u rd | _d S | | d S r   )r$   r   r   r%   r'   r&   r#   update)selfr   r   r   r   r   __init__d   s   
zTimeout.__init__c                 C   s   t jdtdd |   | S )Nz>with timeout() is deprecated, use async with timeout() instead   )
stacklevel)warningswarnDeprecationWarning	_do_enterr)   r   r   r   	__enter__q   s   zTimeout.__enter__exc_typeexc_valexc_tbc                 C   s   |  | d S r   _do_exitr)   r3   r4   r5   r   r   r   __exit__z   s   
zTimeout.__exit__c                    s   |    | S r   )r0   r1   r   r   r   
__aenter__   s   zTimeout.__aenter__c                    s   |  | d S r   r6   r8   r   r   r   	__aexit__   s   
zTimeout.__aexit__c                 C   s   | j tjkS )z$Is timeout expired during execution?)r%   r   r   r1   r   r   r   expired   s   zTimeout.expiredc                 C   s   | j S r   )r#   r1   r   r   r   r      s   zTimeout.deadlinec                 C   s0   | j tjtjfvrtd| j j |   dS )z Reject scheduled timeout if any.invalid state N)r%   r   r   r   RuntimeErrorvalue_rejectr1   r   r   r   reject   s   zTimeout.rejectc                 C   s(   d | _ | jd ur| j  d | _d S d S r   )r'   r&   cancelr1   r   r   r   r@      s
   


zTimeout._rejectr   c                 C   s(   | j }|du rtd| ||  dS )zAdvance timeout on delay seconds.

        The delay can be negative.

        Raise RuntimeError if shift is called when deadline is not scheduled
        Nz1cannot shift timeout if deadline is not scheduled)r#   r>   r(   )r)   r   r   r   r   r   shift   s   zTimeout.shiftc                 C   s^   | j tjkr
td| j tjkrtd| jdur| j  || _| j tjkr-| 	  dS dS )aT  Set deadline to absolute value.

        deadline argument points on the time in the same clock system
        as loop.time().

        If new deadline is in the past the timeout is raised immediately.

        Please note: it is not POSIX time but a time with
        undefined starting base, e.g. the time of the system power on.
        z1cannot reschedule after exit from context managerz!cannot reschedule expired timeoutN)
r%   r   r   r>   r   r&   rB   r#   r   _reschedule)r)   r   r   r   r   r(      s   

zTimeout.updatec                 C   s|   | j tjksJ | j}|d u rd S | j }| jd ur | j  t	 | _
||kr3| j| j| _d S | j|| j| _d S r   )r%   r   r   r#   r$   r   r&   rB   r   current_taskr'   	call_soon_on_timeoutcall_at)r)   r   nowr   r   r   rD      s   



zTimeout._reschedulec                 C   s2   | j tjkrtd| j j tj| _ |   d S )Nr=   )r%   r   r   r>   r?   r   rD   r1   r   r   r   r0      s   zTimeout._do_enterc                 C   sT   |t ju r | jtjkr | jd usJ t| j d | _d | _t jtj	| _| 
  d S r   )r   CancelledErrorr%   r   r   r'   r   r&   TimeoutErrorr   r@   )r)   r3   r   r   r   r7      s   
zTimeout._do_exitc                 C   s*   | j d usJ | j   tj| _d | _d S r   )r'   rB   r   r   r%   r&   r1   r   r   r   rG      s   

zTimeout._on_timeout)r   r   )r   N)r    r!   r"   	__slots__r   floatr   AbstractEventLoopr*   r2   r   BaseExceptionr   boolr9   r:   r;   propertyr<   r   rA   r@   rC   r(   rD   r0   r7   rG   r   r   r   r   r   O   sR    

	


	

	



)r	   r
   r   N)r   enumsysr-   typesr   typingr   r   version_infor   typing_extensionsr   __version____all__rM   r   r   Enumr   r   r   r   r   r   <module>   s&    


