U
    Rh                     @  s   d dl mZ d dlZd dlmZ d dlmZ d dlmZ ddl	m
Z
mZ dd	lmZ G d
d dee Ze ZG dd dZedddddddZdddddddZddddZddddZdS )     )annotationsN)	Generator)contextmanager)TracebackType   )	TaskGroup
TaskStatus   )get_async_backendc                   @  s   e Zd ZddddddZdS )_IgnoredTaskStatusNobjectNonevaluereturnc                 C  s   d S N selfr   r   r   8./venv/lib/python3.8/site-packages/anyio/_core/_tasks.pystarted   s    z_IgnoredTaskStatus.started)N)__name__
__module____qualname__r   r   r   r   r   r      s   r   c                   @  s   e Zd ZdZejddddd dddZd	d
ddZedd
ddZ	e	j
dd	dddZ	edd
ddZedd
ddZedd
ddZej
dd	dddZd d
ddZddddd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shieldfloatbool)r   r   r   c                C  s   t  j||dS )N)r   r   )r
   create_cancel_scope)clsr   r   r   r   r   __new__   s    zCancelScope.__new__r   r   c                 C  s   t dS )zCancel this scope immediately.NNotImplementedErrorr   r   r   r   cancel!   s    zCancelScope.cancelc                 C  s   t dS )z
        The time (clock value) when this scope is cancelled automatically.

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

        Nr$   r&   r   r   r   r   %   s    zCancelScope.deadliner   c                 C  s   t d S r   r$   r   r   r   r   r   /   s    c                 C  s   t dS )z+``True`` if :meth:`cancel` has been called.Nr$   r&   r   r   r   cancel_called3   s    zCancelScope.cancel_calledc                 C  s   t dS )a  
        ``True`` if this scope suppressed a cancellation exception it itself raised.

        This is typically used to check if any work was interrupted, or to see if the
        scope was cancelled due to its deadline being reached. The value will, however,
        only be ``True`` if the cancellation was triggered by the scope itself (and not
        an outer scope).

        Nr$   r&   r   r   r   cancelled_caught8   s    zCancelScope.cancelled_caughtc                 C  s   t dS )z
        ``True`` if this scope is shielded from external cancellation.

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

        Nr$   r&   r   r   r   r   E   s    zCancelScope.shieldc                 C  s   t d S r   r$   r   r   r   r   r   O   s    c                 C  s   t d S r   r$   r&   r   r   r   	__enter__S   s    zCancelScope.__enter__ztype[BaseException] | NonezBaseException | NonezTracebackType | Nonezbool | None)exc_typeexc_valexc_tbr   c                 C  s   t d S r   r$   )r   r+   r,   r-   r   r   r   __exit__V   s    zCancelScope.__exit__N)r   r   r   __doc__mathinfr"   r'   propertyr   setterr(   r)   r   r*   r.   r   r   r   r   r      s&    		r   Fzfloat | Noner   z"Generator[CancelScope, None, None])delayr   r   c              	   c  s\   t  j}| dk	r| |  ntj}t  j||d}|V  W 5 Q R X |jrX| |jkrXtd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.CancelScope`\]

    Nr   )r
   current_timer0   r1   r    r)   r   TimeoutError)r4   r   r5   r   Zcancel_scoper   r   r   
fail_after_   s     r7   c                 C  s,   | dk	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
   r5   r0   r1   r    )r4   r   r   r   r   r   move_on_aftery   s    r8   r   r#   c                   C  s
   t   S )a?  
    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 (or ``float('inf')`` if
        there is no deadline in effect, or ``float('-inf')`` if the current scope has
        been cancelled)
    :rtype: float

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

    :return: a task group

    )r
   create_task_groupr   r   r   r   r:      s    r:   )F)F)Z
__future__r   r0   Zcollections.abcr   
contextlibr   typesr   Z
abc._tasksr   r   Z
_eventloopr
   r   r   ZTASK_STATUS_IGNOREDr   r7   r8   r9   r:   r   r   r   r   <module>   s   K 