
    69j                       d dl mZ d dlZd dlmZmZ d dlmZmZ d dl	m
Z
 d dlmZ d dlmZmZmZmZ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lmZmZ nd dlmZmZ erddlmZmZ  edd      Z eddd      Z ed      ZdddZ	 	 	 	 	 	 	 	 ddZ  G d dee         Z! G d de      Z"y)    )annotationsN)ABCMetaabstractmethod)Callable	Coroutine)Context)TracebackType)TYPE_CHECKINGAnyLiteralProtocolfinaloverload)      )TypeVar)r      )TypeVarTupleUnpack   )CancelScope
TaskHandleT_coT)	covariantT_contra)contravariantdefaultPosArgsTc                    |t        |      S t        | dd       }t        | dd       }dj                  ||fD cg c]  }|s|	 c}      S c c}w )N
__module____qualname__.)strgetattrjoin)funcoverridemodulequalnamexs        P/media/conek/DATA/Code/OCR/venv/lib/python3.12/site-packages/anyio/abc/_tasks.pyget_callable_namer,      sR    8}T<.Ft^T2H88 281aQ8998s   AAc                     | |i |}t        |t              s;t        | d      r| j                   dnd}t	        d| | j
                   d|d      |S )z
    Call the given function with the given positional and keyword arguments.

    :return: the resulting coroutine
    :raises TypeError: if the return value was not a coroutine object

    r    r"    z	Expected z0() to return a coroutine, but the return value (z) is not a coroutine object)
isinstancer   hasattrr    	TypeErrorr!   )r&   argskwargscoroprefixs        r+   call_for_coroutiner6   %   sr       DdI&*1$*EDOO$A&2x 1 12 3!!%(CE
 	

 K    c                  :    e Zd Zedd       Zedd       ZdddZy)	
TaskStatusc                     y N selfs    r+   startedzTaskStatus.started=   s    14r7   c                     y r;   r<   r>   values     r+   r?   zTaskStatus.started@   s    03r7   Nc                     y)zx
        Signal that the task has started.

        :param value: object passed back to the starter of the task
        Nr<   rA   s     r+   r?   zTaskStatus.startedC       r7   )r>   zTaskStatus[None]returnNone)rB   r   rE   rF   r;   )rB   zT_contra | NonerE   rF   )__name__r    r!   r   r?   r<   r7   r+   r9   r9   <   s#    4 43 3r7   r9   c                  *   e Zd ZU dZded<   dddZeddd	 	 	 	 	 	 	 dd       Zedd	 	 	 	 	 	 	 dd	       Z	e
dd
d	 	 	 	 	 	 	 	 	 dd       Ze
dd	 	 	 	 	 	 	 	 	 dd       Zeddd	 	 	 	 	 	 	 	 	 dd       Zedd       Ze	 	 	 	 	 	 	 	 dd       Zy)	TaskGroupa   
    Groups several asynchronous tasks together.

    :ivar cancel_scope: the cancel scope inherited by all child tasks
    :vartype cancel_scope: CancelScope

    .. note:: On asyncio, support for eager task factories is considered to be
        **experimental**. In particular, they don't follow the usual semantics of new
        tasks being scheduled on the next iteration of the event loop, and may thus
        cause unexpected behavior in code that wasn't written with such semantics in
        mind.
    r   cancel_scopeNc                :    | j                   j                  |       y)a
  
        Cancel this task group's cancel scope immediately.

        This is a shortcut for calling ``.cancel_scope.cancel()`` on the task group.

        :param reason: a message describing the reason for the cancellation

        .. versionadded:: 4.14.0

        N)rJ   cancel)r>   reasons     r+   rL   zTaskGroup.cancel[   s     	  (r7   )namecontextc                    y)a-  
        Create a new task from a coroutine object and schedule it to run.

        :param coro: a coroutine object
        :param name: optional name to give the task
        :param context: optional context to run the task in
        :return: a task handle

        .. versionadded:: 4.14.0
        Nr<   )r>   r4   rN   rO   s       r+   create_taskzTaskGroup.create_taskh   rD   r7   rN   c               T    t        ||      }| j                  t        ||      |      S )a  
        Start a new task in this task group.

        :param func: a coroutine function
        :param args: positional arguments to call the function with
        :param name: name of the task, for the purposes of introspection and debugging
        :return: a task handle

        .. versionadded:: 3.0
        .. versionchanged:: 4.14.0
            This method now returns a task handle.

        rR   )r,   rQ   r6   )r>   r&   rN   r2   
final_names        r+   
start_soonzTaskGroup.start_soon{   s.    ( 'tT2
 24 >ZPPr7   .)rN   return_handlec                  K   y wr;   r<   r>   r&   rN   rV   r2   s        r+   startzTaskGroup.start   s         c                  K   y wr;   r<   rX   s        r+   rY   zTaskGroup.start   s      !$rZ   Fc                  K   yw)av  
        Start a new task and wait until it signals for readiness.

        The target callable must accept a keyword argument ``task_status`` (of type
        :class:`TaskStatus`). Awaiting on this method will return whatever was passed to
        ``task_status.started()`` (``None`` by default).

        .. note:: The :class:`TaskStatus` class is generic, and the type argument should
            indicate the type of the value that will be passed to
            ``task_status.started()``.

        :param func: a coroutine function that accepts the ``task_status`` keyword
            argument
        :param args: positional arguments to call the function with
        :param name: an optional name for the task, for introspection and debugging
        :param return_handle: if ``True``, return a :class:`TaskHandle` which also
            contains the start value in ``start_value``
        :return: the value passed to ``task_status.started()``
        :raises RuntimeError: if the task finishes without calling
            ``task_status.started()``

        .. seealso:: :ref:`start_initialize`

        .. versionadded:: 3.0
        Nr<   rX   s        r+   rY   zTaskGroup.start        rZ   c                   K   yw)z:Enter the task group context and allow starting new tasks.Nr<   r=   s    r+   
__aenter__zTaskGroup.__aenter__   r]   rZ   c                   K   yw)z<Exit the task group context waiting for all tasks to finish.Nr<   )r>   exc_typeexc_valexc_tbs       r+   	__aexit__zTaskGroup.__aexit__   r]   rZ   r;   )rM   z
str | NonerE   rF   )r4   Coroutine[Any, Any, T_co]rN   objectrO   zContext | NonerE   TaskHandle[T_co])r&   7Callable[[Unpack[PosArgsT]], Coroutine[Any, Any, T_co]]r2   zUnpack[PosArgsT]rN   rf   rE   rg   )
r&   (Callable[..., Coroutine[Any, Any, T_co]]r2   rf   rN   rf   rV   zLiteral[False]rE   r   )
r&   ri   r2   rf   rN   rf   rV   zLiteral[True]rE   zTaskHandle[T_co, Any])
r&   ri   r2   rf   rN   rf   rV   zLiteral[False] | Literal[True]rE   r   )rE   rI   )ra   ztype[BaseException] | Nonerb   zBaseException | Nonerc   zTracebackType | NonerE   bool)rG   r    r!   __doc____annotations__rL   r   rQ   r   rU   r   rY   r_   rd   r<   r7   r+   rI   rI   K   s    ) 
 "&' 	
   
 $ 
 	QEQ  Q 	Q
 
Q Q, 
 (+6  	
 & 
  
 	$6$ $ 	$
 %$ 
$ $ 
 8=6  	
 6 
 B I I K,K &K %	K
 
K Kr7   rI   )	metaclassr;   )r&   r   r'   rf   rE   r#   )r&   rh   r2   ztuple[Unpack[PosArgsT]]r3   r   rE   re   )#
__future__r   sysabcr   r   collections.abcr   r   contextvarsr   typesr	   typingr
   r   r   r   r   r   version_infor   typing_extensionsr   r   _core._tasksr   r   r   r   r   r,   r6   r9   rI   r<   r7   r+   <module>rx      s    " 
 ' /   I Iw)w++66v&:T4@
#:
A
!  	.(# FK' FKr7   