B
    u9a{)                 @   s   d dl Z d dlZd dlmZmZ ddddgZG dd dZG dd deZdd	dZe	d
krd dl
Z
e
 Zejdddd e Zejse jjrdZndZee dS )    N)CommandCompilercompile_commandInteractiveInterpreterInteractiveConsoleinteractr   c               @   sB   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 krdd d}|| _ t | _d S )NZ__console__)__name____doc__)localsr   compile)selfr	    r   /usr/lib/python3.7/code.py__init__   s    	
zInteractiveInterpreter.__init__<input>singlec          
   C   sR   y|  |||}W n$ tttfk
r6   | | dS X |d krDdS | | dS )NFT)r
   OverflowErrorSyntaxError
ValueErrorshowsyntaxerrorruncode)r   sourcefilenamesymbolcoder   r   r   	runsource&   s    

z InteractiveInterpreter.runsourcec             C   s>   yt || j W n( tk
r&    Y n   |   Y nX d S )N)execr	   
SystemExitshowtraceback)r   r   r   r   r   r   M   s    zInteractiveInterpreter.runcodec             C   s   t  \}}}|t _|t _|t _|rp|tkrpy|j\}\}}}}	W n tk
rV   Y nX t|||||	f}|t _t jt j	krt
||}
| d|
 n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 _zPt|d |d |j}t jt j	krT| 
d| nt |d |d | W d d  }}X d S )Nr      r   )r   r    r!   r"   r#   r'   format_exceptiontb_nextr%   r&   r)   r*   )r   Zlast_tbZeir2   r   r   r   r      s    z$InteractiveInterpreter.showtracebackc             C   s   t j| d S )N)r   stderrr)   )r   datar   r   r   r)      s    zInteractiveInterpreter.write)N)r   r   )N)	r   
__module____qualname__r   r   r   r   r   r)   r   r   r   r   r      s   	

'
#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 )N)r   r   r   resetbuffer)r   r	   r   r   r   r   r      s    
zInteractiveConsole.__init__c             C   s
   g | _ d S )N)buffer)r   r   r   r   r;      s    zInteractiveConsole.resetbufferc             C   sP  y
t j W n tk
r$   dt _Y nX y
t j W n tk
rJ   dt _Y nX d}|d krx| dt jt j|| jjf  n|r| dt	|  d}xyP|rt j}nt j}y| 
|}W n  tk
r   | d P Y nX | |}W q tk
r   | d |   d}Y qX qW |d kr4| d	| jj  n|d
krL| d|  d S )Nz>>> z... zFType "help", "copyright", "credits" or "license" for more information.zPython %s on %s
%s
(%s)
z%s
r   
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promptr1   r   r   r   r      sF    






zInteractiveConsole.interactc             C   s6   | j | d| j }| || j}|s2|   |S )Nr=   )r<   appendr*   r   r   r;   )r   r1   r   rI   r   r   r   rE      s    zInteractiveConsole.pushr   c             C   s   t |S )N)input)r   rJ   r   r   r   rC     s    zInteractiveConsole.raw_input)Nr:   )NN)r   )r   r8   r9   r   r;   r   rE   rC   r   r   r   r   r      s
   

6c             C   sJ   t |}|d k	r||_n"ydd l}W n tk
r8   Y nX || | d S )Nr   )r   rC   readlineImportErrorr   )rG   ZreadfuncZlocalrH   ZconsolerM   r   r   r   r     s    __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quietrG   r   r   r   r   <module>   s$    t
