o
    éT•j]"  ã                   @   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 )NÚPYTHONASYNCIODEBUG)ÚsysÚflagsÚdev_modeÚignore_environmentÚboolÚosÚenvironÚget© r   r   ú)/usr/lib/python3.10/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r| 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 ©Nr   ©r!   r   r   r   Ú__iter__7   ó   zCoroWrapper.__iter__c                 C   s   | j  d ¡S r.   ©r   Úsendr/   r   r   r   Ú__next__:   ó   zCoroWrapper.__next__c                 C   s   | j  |¡S r.   r2   )r!   Úvaluer   r   r   r3   =   r5   zCoroWrapper.sendc                 C   s   | j  |||¡S r.   )r   Úthrow)r!   Útyper6   Ú	tracebackr   r   r   r7   @   s   zCoroWrapper.throwc                 C   s
   | j  ¡ S r.   )r   Úcloser/   r   r   r   r:   C   s   
zCoroWrapper.closec                 C   ó   | j jS r.   )r   Úgi_framer/   r   r   r   r<   F   ó   zCoroWrapper.gi_framec                 C   r;   r.   )r   Ú
gi_runningr/   r   r   r   r>   J   r=   zCoroWrapper.gi_runningc                 C   r;   r.   )r   Úgi_coder/   r   r   r   r?   N   r=   zCoroWrapper.gi_codec                 C   r-   r.   r   r/   r   r   r   Ú	__await__R   r1   zCoroWrapper.__await__c                 C   r;   r.   )r   Úgi_yieldfromr/   r   r   r   rA   U   r=   zCoroWrapper.gi_yieldfromc                 C   sˆ   t | dd ƒ}t |dd ƒ}|d ur@|jdkrB| ›d�}t | ddƒ}|r9d t |¡¡}|dtj› d	�7 }|| ¡ 7 }t 	|¡ d S d S d S )
Nr   r<   r#   z was never yielded fromr   r   Ú zB
Coroutine object created at (most recent call last, truncated to z last lines):
)
r    Úf_lastiÚjoinr9   Úformat_listr   ÚDEBUG_STACK_DEPTHÚrstripr	   Úerror)r!   r   r+   ÚmsgÚtbr   r   r   Ú__del__Y   s   

þ÷zCoroWrapper.__del__r.   )NN)r   Ú
__module__r   r"   r,   r0   r4   r3   r7   r:   Úpropertyr<   r>   r?   r@   rA   rK   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
s,ˆ }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                  ?   sz   � ˆ | i |¤Ž}t  |¡st |¡st|tƒr|E d H }|S z|j}W n
 ty-   Y |S w t|tj	j
ƒr;|ƒ E d H }|S r.   )r   Úisfuturer   r   Ú
isinstancer   r@   ÚAttributeErrorÚcollectionsÚabcÚ	Awaitable)ÚargsÚkwÚresÚ
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 )NrZ   r#   r   r   )r   r   r    r   r   )rV   ÚkwdsÚw©r[   r   r   r   Úwrapper�   s   zcoroutine.<locals>.wrapper)ÚwarningsÚwarnÚDeprecationWarningr   r   ÚisgeneratorfunctionÚ	functoolsÚwrapsÚtypesr   Ú_DEBUGÚ_is_coroutine)r   r_   r   r^   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.rh   N)r   r   r    rh   rZ   r   r   r   r   ¤   s   
ÿr   c                 C   s<   t | ƒtv rdS t| tƒrttƒdk rt t | ƒ¡ dS dS )z)Return True if obj is a coroutine object.Téd   F)r8   Ú_iscoroutine_typecacherQ   Ú_COROUTINE_TYPESÚlenÚadd)Úobjr   r   r   r   ±   s   
r   c           
         sp  t | ƒsJ ‚t| tƒ‰ ‡ fdd„}dd„ }d }t| dƒr#| jr#| j}nt| dƒr.| jr.| j}|| ƒ}|s?|| ƒr=|› d�S |S d }t| dƒrM| jrM| j}nt| d	ƒrX| jrX| j}|jp\d
}d}ˆ r–| j	d ur–t
 | j	¡s–t | j	¡}|d urz|\}}|d u rŠ|› d|› d|› �}	|	S |› d|› d|› �}	|	S |d ur©|j}|› d|› d|› �}	|	S |j}|› d|› d|› �}	|	S )Nc                    s`   ˆ r
t  | jdi ¡S t| dƒr| jr| j}nt| dƒr"| jr"| j}n	dt| ƒj› d�}|› d�S )Nr   r   r   r%   z without __name__>z())r   Ú_format_callbackr   Úhasattrr   r   r8   )r[   Ú	coro_name©Úis_corowrapperr   r   Úget_nameÆ   s   
z#_format_coroutine.<locals>.get_namec                 S   s<   z| j W S  ty   z| jW  Y S  ty   Y Y dS w w )NF)Ú
cr_runningrR   r>   )r[   r   r   r   Ú
is_running×   s   ÿýz%_format_coroutine.<locals>.is_runningÚcr_coder?   z runningr<   Úcr_framez<empty co_filename>r   z done, defined at r$   z running, defined at z running at )r   rQ   r   rp   rw   r?   r<   rx   Úco_filenamer   r   rc   r   Ú_get_function_sourceÚf_linenoÚco_firstlineno)
r[   rt   rv   Ú	coro_coderq   Ú
coro_frameÚfilenameÚlinenoÚsourcer*   r   rr   r   r(   Á   sP   
	



ÿö
øýr(   ) Ú__all__Úcollections.abcrS   rd   r   r   r   r9   rf   r`   rB   r   r   r   Úlogr	   r   rg   r   r   Úobjectrh   r   ÚCoroutineTypeÚGeneratorTyperT   Ú	Coroutinerk   Úsetrj   r   r(   r   r   r   r   Ú<module>   s2    E8ÿ