a
    ze                     @   sF  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	Z	ddl
mZ G dd dejZG dd dejZedkrBe Zee d	eiZd
D ]Ze e ee< qeeeZdadazd dlZW n ey   Y n0 e Zde_e  ze  W n4 e y:   tr2t! s2t"  daY qY q0 qBqdS )    N   )futuresc                       s$   e Zd Z fddZdd Z  ZS )AsyncIOInteractiveConsolec                    s*   t  | | jj jtjO  _|| _d S )N)super__init__compileZcompilerflagsastZPyCF_ALLOW_TOP_LEVEL_AWAITloop)selflocalsr
   	__class__ &/usr/lib/python3.9/asyncio/__main__.pyr      s    z"AsyncIOInteractiveConsole.__init__c                    sp   t j  fdd}t| z
 W S  tyB    Y n* tyj   tr^	d n
  Y n0 d S )Nc               
      s   d a dat j} z
|  }W nt ty4    Y nb tyf } zda| W Y d }~d S d }~0  ty } z| W Y d }~d S d }~0 0 t	
|s| d S zj|a tt  W n0 t y } z| W Y d }~n
d }~0 0 d S )NFT)repl_futurerepl_future_interruptedtypesFunctionTyper   
SystemExitKeyboardInterruptset_exceptionBaseExceptioninspectZiscoroutine
set_resultr
   Zcreate_taskr   Z_chain_future)funccoroexexccodefuturer   r   r   callback   s,    




z3AsyncIOInteractiveConsole.runcode.<locals>.callbackz
KeyboardInterrupt
)
concurrentr   Futurer
   call_soon_threadsaferesultr   r   r   writeZshowtraceback)r   r    r"   r   r   r   runcode   s    


z!AsyncIOInteractiveConsole.runcode)__name__
__module____qualname__r   r(   __classcell__r   r   r   r   r      s   r   c                   @   s   e Zd Zdd ZdS )
REPLThreadc                 C   sv   zRdt j dt j dtt dd d}tj|dd W tjd	d
td t	
t	j ntjd	d
td t	
t	j 0 d S )Nzasyncio REPL z on zy
Use "await" directly instead of "asyncio.run()".
Type "help", "copyright", "credits" or "license" for more information.
Zps1z>>> zimport asynciozexiting asyncio REPL...)bannerZexitmsgignorez ^coroutine .* was never awaited$)messagecategory)sysversionplatformgetattrconsoleZinteractwarningsfilterwarningsRuntimeWarningr
   r%   stop)r   r.   r   r   r   runF   s*    
zREPLThread.runN)r)   r*   r+   r;   r   r   r   r   r-   D   s   r-   __main__asyncio>   
__loader__r)   __spec____package____file____builtins__FT)#r	   r=   r    concurrent.futuresr#   r   r2   	threadingr   r7    r   ZInteractiveConsoler   Threadr-   r)   Znew_event_loopr
   Zset_event_loopZrepl_localskeyr   r6   r   r   readlineImportErrorZrepl_threaddaemonstartZrun_foreverr   donecancelr   r   r   r   <module>   sF   6



