Current File : //usr/local/apps/python3/lib/python3.11/site-packages/asgiref/__pycache__/timeout.cpython-311.pyc
�

�rRh+��X�ddlZddlZddlmZddlmZddlmZmZGd�d��ZdS)�N)�
TracebackType)�Any)�Optional�Typec	�"�eZdZdZdd�deedeejddfd�Zdd�Z	de
ed	ed
edee
fd�Zdd�Zde
ed	ed
eddfd
�Zede
fd���Zedeefd���Zdd�Zde
eddfd�Zdd�ZdS)�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��||_|�tj��}ntjdt
��||_d|_d|_d|_	d|_
dS)Nz-The loop argument to timeout() is deprecated.F)�_timeout�asyncio�get_running_loop�warnings�warn�DeprecationWarning�_loop�_task�
_cancelled�_cancel_handler�
_cancel_at)�selfrr	s   �G/usr/local/apps/python3/lib/python3.11/site-packages/asgiref/timeout.py�__init__ztimeout.__init__sd�� ��
��<��+�-�-�D�D��M�C�EW�
�
�
���
���
����#��������c�*�|���S�N��	_do_enter�rs r�	__enter__ztimeout.__enter__2s���~�~���r�exc_type�exc_val�exc_tbc�0�|�|��dSr��_do_exit�rr!r"r#s    r�__exit__ztimeout.__exit__5s��	
�
�
�h�����trc��.K�|���Srrrs r�
__aenter__ztimeout.__aenter__>s�����~�~���rc��4K�|�|��dSrr%r's    r�	__aexit__ztimeout.__aexit__As ����	
�
�
�h�����rc��|jSr)rrs r�expiredztimeout.expiredIs
����rc�r�|j�/t|j|j���z
d��SdS)Ng)r�maxr�timers r�	remainingztimeout.remainingMs2���?�&��t������):�):�:�C�@�@�@��4rc�x�|j�|Stj|j��|_|j�td���|jdkr!|j�|j��|S|j���|jz|_	|j�
|j	|j��|_|S)Nz4Timeout context manager should be used inside a taskr)rr
�current_taskrr�RuntimeError�	call_soon�_cancel_taskr1r�call_atrrs rrztimeout._do_enterTs����=� ��K��)�$�*�5�5��
��:���I���
��=�A����J� � ��!2�3�3�3��K��*�/�/�+�+�d�m�;���#�z�1�1�$�/�4�CT�U�U����rc���|tjur!|jrd|_d|_tj�|j�'|j� |j���d|_d|_dSr)r
�CancelledErrorrrr�TimeoutErrorr�cancel)rr!s  rr&ztimeout._do_exithsh���w�-�-�-�$�/�-�#'�D� ��D�J��&�&��=�$��)=�)I�� �'�'�)�)�)�#'�D� ���
��trc�X�|j�"|j���d|_dSdS)NT)rr<rrs rr7ztimeout._cancel_taskss1���:�!��J������"�D�O�O�O�"�!r)r
r)r
N)�__name__�
__module__�__qualname__�__doc__r�floatr
�AbstractEventLooprr r�
BaseExceptionr�boolr(r*r,�propertyr.r2rr&r7�rrrrs���������$59�	����%����w�0�1�	�

�����& � � � ���}�%�����	�

�$������ � � � � ��}�%� �� ��	 �

� � � � ��������X����8�E�?�����X������(	��m�!4�	��	�	�	�	�#�#�#�#�#�#rr)	r
r�typesr�typingrrrrrGrr�<module>rJs�����������������������!�!�!�!�!�!�!�!�f#�f#�f#�f#�f#�f#�f#�f#�f#�f#r