o
    IAf~)                     @   s   	 d dl Z d dlZd dlmZmZ g dZG dd dZG dd deZddd	Ze	d
krSd dl
Z
e
 Zejdddd e ZejsHe jjrKdZndZee dS dS )    N)CommandCompilercompile_command)InteractiveInterpreterInteractiveConsoleinteractr   c                   @   sD   e Zd Z	 dddZdddZdd	 Zdd
dZdd Zdd ZdS )r   Nc                 C   s&   	 |d u r
dd d}|| _ t | _d S )NZ__console__)__name____doc__)localsr   compile)selfr	    r   /usr/lib/python3.10/code.py__init__   s
   
zInteractiveInterpreter.__init__<input>singlec              
   C   sT   	 z	|  |||}W n tttfy   | | Y dS w |d u r#dS | | dS )NFT)r
   OverflowErrorSyntaxError
ValueErrorshowsyntaxerrorruncode)r   sourcefilenamesymbolcoder   r   r   	runsource&   s   

z InteractiveInterpreter.runsourcec                 C   s8   	 z	t || j W d S  ty       |   Y d S N)execr	   
SystemExitshowtraceback)r   r   r   r   r   r   M   s   zInteractiveInterpreter.runcodec                 C   s   	 t  \}}}|t _|t _|t _|r8|tu r8z|j\}\}}}}	W n	 ty+   Y nw t|||||	f}|t _t jt j	u rNt
||}
| d|
 d S t ||| d S )N )sysexc_info	last_type
last_valuelast_tracebackr   argsr   
excepthook__excepthook__	tracebackformat_exception_onlywritejoin)r   r   typevaluetbmsgZdummy_filenamelinenooffsetlinelinesr   r   r   r   `   s"   z&InteractiveInterpreter.showsyntaxerrorc                 C   s   	 t   \t _t _}}|t _z4t|d |d |j}t jt j	u r+| 
d| nt |d |d | W d  }}d S W d  }}d S d  }}w )Nr      r   )r    r!   r"   r#   r$   r(   format_exceptiontb_nextr&   r'   r*   r+   )r   Zlast_tbeir3   r   r   r   r      s   z$InteractiveInterpreter.showtracebackc                 C   s   	 t j| d S r   )r    stderrr*   )r   datar   r   r   r*      s   zInteractiveInterpreter.writer   )r   r   )	r   
__module____qualname__r   r   r   r   r   r*   r   r   r   r   r      s    

'
#r   c                   @   s<   e Zd Z	 dddZdd ZdddZd	d
 ZdddZdS )r   N	<console>c                 C   s    	 t | | || _|   d S r   )r   r   r   resetbuffer)r   r	   r   r   r   r   r      s   	zInteractiveConsole.__init__c                 C   s   	 g | _ d S r   )buffer)r   r   r   r   r=      s   
zInteractiveConsole.resetbufferc                 C   sH  	 zt j W n ty   dt _Y nw zt j W n ty$   dt _Y nw d}|d u r;| dt jt j|| jjf  n|rF| dt	|  d}	 z'|rPt j}nt j}z| 
|}W n tyi   | d Y W nw | |}W n ty   | d	 |   d}Y nw qI|d u r| d
| jj  d S |dkr| d|  d S d S )Nz>>> z... zFType "help", "copyright", "credits" or "license" for more information.zPython %s on %s
%s
(%s)
z%s
r   r4   
z
KeyboardInterrupt
znow exiting %s...
r   )r    Zps1AttributeErrorZps2r*   versionplatform	__class__r   str	raw_inputEOFErrorpushKeyboardInterruptr=   )r   bannerexitmsgZcprtmorepromptr2   r   r   r   r      sX   






zInteractiveConsole.interactc                 C   s8   	 | j | d| j }| || j}|s|   |S )Nr?   )r>   appendr+   r   r   r=   )r   r2   r   rK   r   r   r   rG      s   zInteractiveConsole.pushr   c                 C   s
   	 t |S r   )input)r   rL   r   r   r   rE     s   
zInteractiveConsole.raw_input)Nr<   )NN)r   )r   r:   r;   r   r=   r   rG   rE   r   r   r   r   r      s    

6r   c                 C   sJ   	 t |}|d ur||_nzdd l}W n	 ty   Y nw || | d S )Nr   )r   rE   readlineImportErrorr   )rI   ZreadfunclocalrJ   ZconsolerO   r   r   r   r     s   r   __main__z-q
store_truez*don't print version and copyright messages)actionhelpr   )NNNN)r    r(   Zcodeopr   r   __all__r   r   r   r   argparseArgumentParserparseradd_argument
parse_argsr%   qflagsquietrI   r   r   r   r   <module>   s*     
t