a
    ´i]"  ã                   @   sÔ   d Z ddlZddlZddlZddlZddlZddlZddl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 dd	„ Zeƒ ZG d
d„ dƒZdd„ Zeƒ Zdd„ ZejejejjefZeƒ Zdd„ Zdd„ ZdS ))Ú	coroutineÚiscoroutinefunctionÚiscoroutineé    Né   )Úbase_futures)Ú	constants)Úformat_helpers)Úloggerc                   C   s"   t jjp t jj o ttj d¡ƒS )NZPYTHONASYNCIODEBUG)ÚsysÚflagsÚdev_modeÚignore_environmentÚboolÚosÚenvironÚget© r   r   ú*/usr/lib64/python3.9/asyncio/coroutines.pyÚ_is_debug_mode   s    ÿr   c                   @   sˆ   e Zd Zddd„Zdd„ Zdd„ Zdd	„ Zd
d„ Zddd„Zdd„ Z	e
dd„ ƒZe
dd„ ƒZe
dd„ ƒZdd„ Ze
dd„ ƒZdd„ ZdS )ÚCoroWrapperNc                 C   sZ   t  |¡st  |¡sJ |ƒ‚|| _|| _t t d¡¡| _	t
|dd ƒ| _t
|dd ƒ| _d S )Nr   Ú__name__Ú__qualname__)ÚinspectÚisgeneratorr   ÚgenÚfuncr   Úextract_stackr
   Ú	_getframeÚ_source_tracebackÚgetattrr   r   )Úselfr   r   r   r   r   Ú__init__'   s    zCoroWrapper.__init__c                 C   sJ   t | ƒ}| jr4| jd }|d|d › d|d › �7 }d| jj› d|› d�S )	Néÿÿÿÿz, created at r   ú:r   ú<ú ú>)Ú_format_coroutiner   Ú	__class__r   )r    Ú	coro_reprÚframer   r   r   Ú__repr__/   s
    
zCoroWrapper.__repr__c                 C   s   | S ©Nr   ©r    r   r   r   Ú__iter__7   s    zCoroWrapper.__iter__c                 C   s   | j  d ¡S r,   ©r   Úsendr-   r   r   r   Ú__next__:   s    zCoroWrapper.__next__c                 C   s   | j  |¡S r,   r/   )r    Úvaluer   r   r   r0   =   s    zCoroWrapper.sendc                 C   s   | j  |||¡S r,   )r   Úthrow)r    Útyper2   Ú	tracebackr   r   r   r3   @   s    zCoroWrapper.throwc                 C   s
   | j  ¡ S r,   )r   Úcloser-   r   r   r   r6   C   s    zCoroWrapper.closec                 C   s   | j jS r,   )r   Úgi_framer-   r   r   r   r7   F   s    zCoroWrapper.gi_framec                 C   s   | j jS r,   )r   Ú
gi_runningr-   r   r   r   r8   J   s    zCoroWrapper.gi_runningc                 C   s   | j jS r,   )r   Úgi_coder-   r   r   r   r9   N   s    zCoroWrapper.gi_codec                 C   s   | S r,   r   r-   r   r   r   Ú	__await__R   s    zCoroWrapper.__await__c                 C   s   | j jS r,   )r   Úgi_yieldfromr-   r   r   r   r;   U   s    zCoroWrapper.gi_yieldfromc                 C   s€   t | dd ƒ}t |dd ƒ}|d ur||jdkr|| ›d�}t | ddƒ}|rrd t |¡¡}|dtj› d	�7 }|| ¡ 7 }t 	|¡ d S )
Nr   r7   r"   z was never yielded fromr   r   Ú zB
Coroutine object created at (most recent call last, truncated to z last lines):
)
r   Úf_lastiÚjoinr5   Úformat_listr   ZDEBUG_STACK_DEPTHÚrstripr	   Úerror)r    r   r*   ÚmsgÚtbr   r   r   Ú__del__Y   s    
þ
zCoroWrapper.__del__)N)NN)r   Ú
__module__r   r!   r+   r.   r1   r0   r3   r6   Úpropertyr7   r8   r9   r:   r;   rD   r   r   r   r   r   $   s"   





r   c                    sz   t jdtdd� t ˆ¡rˆS t ˆ¡r.ˆ‰ nt ˆ¡‡fdd„ƒ‰ t 	ˆ ¡‰ t
sXˆ }nt ˆ¡‡ ‡fdd„ƒ}t|_|S )z„Decorator to mark coroutines.

    If the coroutine is not yielded from before it is destroyed,
    an error message is logged.
    zN"@coroutine" decorator is deprecated since Python 3.8, use "async def" insteadé   )Ú
stacklevelc                  ?   st   ˆ | i |¤Ž}t  |¡s,t |¡s,t|tƒr8|E d H }n8z
|j}W n tyT   Y n0 t|tj	j
ƒrp|ƒ E d H }|S r,   )r   Zisfuturer   r   Ú
isinstancer   r:   ÚAttributeErrorÚcollectionsÚabcÚ	Awaitable)ÚargsÚkwÚresZ
await_meth©r   r   r   Úcoroz   s    ÿ
zcoroutine.<locals>.coroc                     sD   t ˆ | i |¤Žˆd�}|jr$|jd= tˆdd ƒ|_tˆdd ƒ|_|S )NrQ   r"   r   r   )r   r   r   r   r   )rN   ÚkwdsÚw©rR   r   r   r   Úwrapper�   s    zcoroutine.<locals>.wrapper)ÚwarningsÚwarnÚDeprecationWarningr   r   ÚisgeneratorfunctionÚ	functoolsÚwrapsÚtypesr   Ú_DEBUGÚ_is_coroutine)r   rV   r   rU   r   r   i   s"    þ


r   c                 C   s   t  | ¡pt| ddƒtu S )z6Return True if func is a decorated coroutine function.r_   N)r   r   r   r_   rQ   r   r   r   r   ¤   s    
ÿr   c                 C   s@   t | ƒtv rdS t| tƒr8ttƒdk r4t t | ƒ¡ dS dS dS )z)Return True if obj is a coroutine object.Téd   FN)r4   Ú_iscoroutine_typecacherI   Ú_COROUTINE_TYPESÚlenÚadd)Úobjr   r   r   r   ±   s    
r   c           
         st  t | ƒsJ ‚t| tƒ‰ ‡ fdd„}dd„ }d }t| dƒrF| jrF| j}nt| dƒr\| jr\| j}|| ƒ}|s~|| ƒrz|› d�S |S d }t| dƒrš| jrš| j}nt| d	ƒr°| jr°| j}|jp¸d
}d}ˆ �r0| j	d u�r0t
 | j	¡�s0t | j	¡}|d urú|\}}|d u �r|› d|› d|› �}	n|› d|› d|› �}	n@|d u�rV|j}|› d|› d|› �}	n|j}|› d|› d|› �}	|	S )Nc                    s`   ˆ rt  | jdi ¡S t| dƒr,| jr,| j}n*t| dƒrD| jrD| j}ndt| ƒj› d�}|› d�S )Nr   r   r   r$   z without __name__>z())r   Z_format_callbackr   Úhasattrr   r   r4   )rR   Ú	coro_name©Zis_corowrapperr   r   Úget_nameÆ   s    z#_format_coroutine.<locals>.get_namec                 S   sD   z| j W S  ty>   z| jW  Y S  ty8   Y Y dS 0 Y n0 d S )NF)Ú
cr_runningrJ   r8   )rR   r   r   r   Ú
is_running×   s    z%_format_coroutine.<locals>.is_runningÚcr_coder9   z runningr7   Úcr_framez<empty co_filename>r   z done, defined at r#   z running, defined at z running at )r   rI   r   rf   rl   r9   r7   rm   Úco_filenamer   r   rZ   r   Z_get_function_sourceÚf_linenoÚco_firstlineno)
rR   ri   rk   Z	coro_coderg   Z
coro_frameÚfilenameÚlinenoÚsourcer)   r   rh   r   r'   Á   sL    
	

ÿ
þ

r'   ) Ú__all__Úcollections.abcrK   r[   r   r   r
   r5   r]   rW   r<   r   r   r   Úlogr	   r   r^   r   r   Úobjectr_   r   ÚCoroutineTypeÚGeneratorTyperL   Ú	Coroutinerb   Úsetra   r   r'   r   r   r   r   Ú<module>   s0   E8ÿ