U
    (–€h  ã                   @  sè  U d dl mZ d dlZd dlZd dlmZmZmZmZ d dl	m
Z
mZmZ d dlZejdkrrd dlmZmZmZ nd dlmZmZmZ eddd	�Zed
ddd�Zedddd�Zeddd�Zeddd	�ZedƒZeddd	�ZdZded< ejdk�r
eeeef Zded< nBejdk�r@eeedef eeeef f Zded< ndZded< G dd„ deeeef eeeef ƒZe�r�G dd„ deje ƒZn,ejdk�r¤ejZnG dd„ dejee ƒZG dd„ dee ƒZd d!d"d#d$œd%d&„Z dS )'é    )ÚannotationsN)ÚAnyÚUnionÚTYPE_CHECKINGÚGeneric)Ú	TypeAliasÚTypeVarÚSelf)é   é	   )Ú	GeneratorÚ	CoroutineÚ	AwaitableÚ
_YieldT_coT)Ú	covariantÚ_SendT_contra)ÚcontravariantÚdefaultÚ_ReturnT_co)r   r   Ú_SendT_contra_nd)r   Ú_ReturnT_co_ndÚ_TÚ_T_cozasyncio.Future[object] | Noner   Ú_TaskYieldType)r
   é   Ú_TaskCompatibleCoroz9Generator[_TaskYieldType, None, _T_co] | Awaitable[_T_co]c                      sf   e Zd Zdddœdd„Zdddœd	d
„Zddœdd„Zdd„ Zddœdd„Zddœ‡ fdd„Z‡  Z	S )Ú_InterceptorzqCoroutine[_YieldT_co, _SendT_contra_nd, _ReturnT_co_nd] | Generator[_YieldT_co, _SendT_contra_nd, _ReturnT_co_nd]zcontextvars.Context)ÚcoroÚcontextc                 C  s   || _ || _d S ©N)Ú_Interceptor__coroÚ_Interceptor__context)Úselfr   r   © r#   ú3/tmp/pip-unpacked-wheel-rrqp3fat/taskgroup/tasks.pyÚ__init__)   s    z_Interceptor.__init__r   r   )ÚvÚreturnc                 C  s   | j  | jj|¡S r   )r!   Úrunr    Úsend)r"   r&   r#   r#   r$   r)   4   s    z_Interceptor.send©r'   c                 G  s   | j j| jjf|žŽ S r   )r!   r(   r    Úthrow)r"   Úexc_infor#   r#   r$   r+   7   s    z_Interceptor.throwc                 C  s   t | j|ƒS r   )Úgetattrr    )r"   Únamer#   r#   r$   Ú__getattr__:   s    z_Interceptor.__getattr__r	   c                 C  s   | S r   r#   ©r"   r#   r#   r$   Ú	__await__=   s    z_Interceptor.__await__ÚNonec                   s   t ƒ  ¡  d S r   )ÚsuperÚcloser0   ©Ú	__class__r#   r$   r4   @   s    z_Interceptor.close)
Ú__name__Ú
__module__Ú__qualname__r%   r)   r+   r/   r1   r4   Ú__classcell__r#   r#   r5   r$   r   %   s   r   c                   @  s   e Zd ZdS ©Ú_TaskN©r7   r8   r9   r#   r#   r#   r$   r<   F   s   r<   c                   @  s   e Zd ZdS r;   r=   r#   r#   r#   r$   r<   N   s   c                      sn   e Zd Zddœdddœ‡ fdd„Zddd	d
œ‡ fdd„Zddœdd„Zddœdd„Zddœ‡ fdd„Z‡  ZS )ÚTaskN)r   ú_TaskCompatibleCoro[_T_co]r2   )r   r'   c                  s0   d| _ |d k	rt||ƒ}tƒ j|f|ž|Ž d S )Nr   )Ú_num_cancels_requestedr   r3   r%   )r"   r   r   ÚargsÚkwargsr5   r#   r$   r%   S   s    
zTask.__init__r   Úbool)rA   rB   r'   c                   s$   |   ¡ s|  jd7  _tƒ j||ŽS )Né   )Údoner@   r3   Úcancel)r"   rA   rB   r5   r#   r$   rF   [   s    zTask.cancelÚintr*   c                 C  s   | j S r   ©r@   r0   r#   r#   r$   Ú
cancelling`   s    zTask.cancellingc                 C  s   | j dkr|  j d8  _ | j S )Nr   rD   rH   r0   r#   r#   r$   Úuncancelc   s    
zTask.uncancelz!_TaskCompatibleCoro[_T_co] | Nonec                   s   t ƒ  ¡ }t|tƒr|jS |S r   )r3   Úget_coroÚ
isinstancer   r    )r"   r   r5   r#   r$   rK   h   s    

zTask.get_coro)	r7   r8   r9   r%   rF   rI   rJ   rK   r:   r#   r#   r5   r$   r>   R   s   ÿr>   zasyncio.AbstractEventLoopr?   r   zTask[_T_co])Úloopr   rB   r'   c                 K  s   t |fd| i|—ŽS )NrM   )r>   )rM   r   rB   r#   r#   r$   Útask_factoryo   s    rN   )!Ú
__future__r   ZasyncioZcontextvarsÚtypingr   r   r   r   Ztyping_extensionsr   r   r	   ÚsysÚversion_infoÚcollections.abcr   r   r   r   r   r   r   r   r   r   r   Ú__annotations__r   r   r>   r<   rN   r#   r#   r#   r$   Ú<module>   sL    
ÿÿÿ

þ