o
    :ήc                     @   s
  d dl Z d dlmZ d dlmZmZ d dlmZ ddlm	Z	m
Z
 ddlmZmZmZ dd	lmZ G d
d de
Ze ZG dd ded ZdddedefddZG dd dee Zd dee dedefddZd dee dedefddZdefddZd!ddZdS )"    N)TracebackType)OptionalType)warn   )	TaskGroup
TaskStatus   )DeprecatedAsyncContextManagerDeprecatedAwaitableDeprecatedAwaitableFloat)get_asynclibc                   @   s    e Zd ZddeddfddZdS )_IgnoredTaskStatusNvaluereturnc                 C   s   d S N selfr   r   r   9/tmp/pip-target-vg8gfxp4/lib/python/anyio/_core/_tasks.pystarted      z_IgnoredTaskStatus.startedr   )__name__
__module____qualname__objectr   r   r   r   r   r      s    r   c                	   @   s   e Zd ZdZejdddededd fddZde	fd	d
Z
edefddZejdeddfddZedefddZedefddZejde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S )CancelScopez
    Wraps a unit of work that can be made separately cancellable.

    :param deadline: The time (clock value) when this scope is cancelled automatically
    :param shield: ``True`` to shield the cancel scope from external cancellation
    Fdeadlineshieldr   r   r   c                C   s   t  j||dS )N)r   r   )r   r   )clsr   r   r   r   r   __new__   s   zCancelScope.__new__c                 C      t )zCancel this scope immediately.NotImplementedErrorr   r   r   r   cancel$      zCancelScope.cancelc                 C   r"   )z
        The time (clock value) when this scope is cancelled automatically.

        Will be ``float('inf')`` if no timeout has been set.

        r#   r%   r   r   r   r   (      zCancelScope.deadliner   Nc                 C   r"   r   r#   r   r   r   r   r   2   r'   c                 C   r"   )z+``True`` if :meth:`cancel` has been called.r#   r%   r   r   r   cancel_called6   s   zCancelScope.cancel_calledc                 C   r"   )z
        ``True`` if this scope is shielded from external cancellation.

        While a scope is shielded, it will not receive cancellations from outside.

        r#   r%   r   r   r   r   ;   r(   zCancelScope.shieldc                 C   r"   r   r#   r   r   r   r   r   E   r'   c                 C   r"   r   r#   r%   r   r   r   	__enter__I   r   zCancelScope.__enter__exc_typeexc_valexc_tbc                 C   r"   r   r#   )r   r+   r,   r-   r   r   r   __exit__L   s   zCancelScope.__exit__)r   r   )r   r   r   __doc__mathinffloatboolr!   r   r&   propertyr   setterr)   r   r*   r   r   BaseExceptionr   r.   r   r   r   r   r      s>    
		

r   Fr   r   r   c                 C   s   t dt t j| dS )z
    Open a cancel scope.

    :param shield: ``True`` to shield the cancel scope from external cancellation
    :return: a cancel scope

    .. deprecated:: 3.0
       Use :class:`~CancelScope` directly.

    z?open_cancel_scope() is deprecated -- use CancelScope() directlyr7   )r   DeprecationWarningr   r   r7   r   r   r   open_cancel_scopeU   s
   r9   c                	   @   sV   e Zd ZdefddZdefddZdeee  dee d	ee	 dee
 fd
dZdS )FailAfterContextManagercancel_scopec                 C   s
   || _ d S r   )_cancel_scope)r   r;   r   r   r   __init__h      
z FailAfterContextManager.__init__r   c                 C   s
   | j  S r   )r<   r*   r%   r   r   r   r*   k   r>   z!FailAfterContextManager.__enter__r+   r,   r-   c                 C   s    | j |||}| j jrt|S r   )r<   r.   r)   TimeoutError)r   r+   r,   r-   retvalr   r   r   r.   n   s   z FailAfterContextManager.__exit__N)r   r   r   r   r=   r*   r   r   r6   r   r3   r.   r   r   r   r   r:   g   s    
r:   delayc                 C   s4   | durt   |  ntj}t  j||d}t|S )a  
    Create a context manager which raises a :class:`TimeoutError` if does not finish in time.

    :param delay: maximum allowed time (in seconds) before raising the exception, or ``None`` to
        disable the timeout
    :param shield: ``True`` to shield the cancel scope from external cancellation
    :return: a context manager that yields a cancel scope
    :rtype: :class:`~typing.ContextManager`\[:class:`~anyio.abc.CancelScope`\]

    Nr   )r   current_timer0   r1   r   r:   )rA   r   r   r;   r   r   r   
fail_after{   s   rC   c                 C   s,   | durt   |  ntj}t  j||dS )aD  
    Create a cancel scope with a deadline that expires after the given delay.

    :param delay: maximum allowed time (in seconds) before exiting the context block, or ``None``
        to disable the timeout
    :param shield: ``True`` to shield the cancel scope from external cancellation
    :return: a cancel scope

    Nr   )r   rB   r0   r1   r   )rA   r   r   r   r   r   move_on_after   s   rD   c                   C   s   t t  tS )z
    Return the nearest deadline among all the cancel scopes effective for the current task.

    :return: a clock value from the event loop's internal clock (``float('inf')`` if there is no
        deadline in effect)
    :rtype: float

    )r   r   current_effective_deadliner   r   r   r   rE      s   	
rE   r   c                   C   s
   t   S )z:
    Create a task group.

    :return: a task group

    )r   r   r   r   r   r   create_task_group   s   
rF   )F)r   r   )r0   typesr   typingr   r   warningsr   
abc._tasksr   r   _compatr
   r   r   
_eventloopr   r   TASK_STATUS_IGNOREDr   r3   r9   r:   r2   rC   rD   rE   rF   r   r   r   r   <module>   s     >