o
    f]"                     @   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 )	Nz, 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 )zDecorator 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.Td   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rt
| j	st| 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