B
    b_                 @   s|   d Z dZed7 ZddlZddlZddlmZmZ ddlmZ ddlm	Z	 ddl
Z
ddlZG d	d
 d
eZG dd deZdS )z%Interpreter executes Python commands.z+Patrick K. O'Brien <pobrien@orbtech.com> / z.David N. Mashburn <david.n.mashburn@gmail.com>    N)InteractiveInterpretercompile_command   )
dispatcher)
introspectc               @   sb   e Zd ZdZddejejejdfddZdddZ	dd	 Z
d
d Zdd ZdddZdddZdS )Interpreterz1Interpreter based on code.InteractiveInterpreter.NTc       	      C   s   t j| |d || _|| _|| _|r8ddlm} ||_~|r`d}|d7 }dtj	tj
tj|f | _y
tj W n tk
r   dt_Y nX y
tj W n tk
r   dt_Y nX d| _g | _d	| _d	S )
z)Create an interactive interpreter object.)localsr   )builtinsz0Type "help", "copyright", "credits" or "license"z for more information.zPython %s on %s%s%sz>>> z... N)r   __init__stdinstdoutstderrZ	six.movesr	   Z	raw_inputsysversionplatformoslinesepZ	introTextps1AttributeErrorps2morecommandBufferZstartupScript)	selfr   rawinr   r   r   ZshowInterpIntror	   	copyright r   0lib/python3.7/site-packages/wx/py/interpreter.pyr
      s0    

zInterpreter.__init__c             C   s   t js6t|tkr6y|d}W n tk
r4   Y nX | js^y| jd= W n tk
r\   Y nX | jsp| j	g  | jd 	| d
| jd }d}|dk	r| | d| _n| | }| _tjd| |||d |S )a  Send command to the interpreter to be executed.

        Because this may be called recursively, we append a new list
        onto the commandBuffer list and then append commands into
        that.  If the passed in command is part of a multi-line
        command we keep appending the pieces to the last list in
        commandBuffer until we have a complete command. If not, we
        delete that last list.zutf-8
FNzInterpreter.push)signalZsendercommandr   source)sixZPY3typeZunicodeencodeUnicodeEncodeErrorr   r   
IndexErrorappendjoin	runModule	runsourcer   send)r   r    ZastModr!   r   r   r   r   push1   s.       
zInterpreter.pushc             C   s   t jt jt j  }}}| j| j| j  t _t _t _t| |}t j| jkrR|t _nt j| _t j| jkrn|t _nt j| _t j| jkr|t _nt j| _|S )z/Compile and run source code in the interpreter.)r   r   r   r   r   r*   )r   r!   r   r   r   r   r   r   r   r*   U   s    	zInterpreter.runsourcec             C   s   t jt jt j  }}}| j| j| j  t _t _t _| t|dd t j| jkrX|t _nt j| _t j| jkrt|t _nt j| _t j| jkr|t _nt j| _dS )z1Compile and run an ast module in the interpreter. ZsingleF)r   r   r   r   Zruncodecompile)r   modr   r   r   r   r   r   r)   q   s    zInterpreter.runModulec             C   s
   t dgS )z(Return list of auto-completion keycodes..)ord)r   r   r   r   getAutoCompleteKeys   s    zInterpreter.getAutoCompleteKeysr-   c             O   sb   t jt jt j  }}}| j| j| j  t _t _t _tj|| jf||}|||  t _t _t _|S )zyReturn list of auto-completion options for a command.

        The list of options will be based on the locals namespace.)r   r   r   r   r   getAutoCompleteListr   )r   r    argskwdsr   r   r   lr   r   r   r3      s    
zInterpreter.getAutoCompleteListc             O   s   t j|| jf||S )zhReturn call tip text for a command.

        Call tip information will be based on the locals namespace.)r   
getCallTipr   )r   r    r4   r5   r   r   r   r7      s    zInterpreter.getCallTip)N)r-   )r-   )__name__
__module____qualname____doc__r   r   r   r   r
   r,   r*   r)   r2   r3   r7   r   r   r   r   r      s   
$
r   c               @   s   e Zd ZdZdddZdS )InterpreterAlaCartezDemo Interpreter.main promptcontinuation promptc             C   s&   t j| |||||d |t_|t_dS )z)Create an interactive interpreter object.)r   r   r   r   r   N)r   r
   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r
      s    
zInterpreterAlaCarte.__init__N)r=   r>   )r8   r9   r:   r;   r
   r   r   r   r   r<      s   r<   )r;   
__author__r   r   coder   r   r-   r   r   Zwxr"   r   r<   r   r   r   r   <module>   s    