
    d                         d Z dZedz  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
e      Z G d de      Zy)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                       e Zd ZdZddej
                  ej                  ej                  dfdZddZ	d Z
d Zd Zdd	Zdd
Zy)Interpreterz1Interpreter based on code.InteractiveInterpreter.NTc                    t        j                  | |       || _        || _        || _        |rddlm} ||_        ~|rBd}|dz  }dt        j                  dt        j                  t        j                  || _        	 t        j                   	 t        j                    d| _        g | _        d
| _        y
# t        $ r dt        _        Y =w xY w# t        $ r d	t        _        Y Fw xY w))Create an interactive interpreter object.)localsr   )builtinsz0Type "help", "copyright", "credits" or "license"z for more information.zPython z on z>>> z... N)r   __init__stdinstdoutstderr	six.movesr   	raw_inputsysversionplatformoslinesep	introTextps1AttributeErrorps2morecommandBufferstartupScript)	selfr   rawinr   r   r   showInterpIntror   	copyrights	            3/usr/lib/python3/dist-packages/wx/py/interpreter.pyr   zInterpreter.__init__   s     	''V<
*!&HJI11I!kk3<<YPDN	GG	GG 	!  	CG	  	CG	s$   B9 C 9CCC*)C*c                 @   t         j                  s$t        |      t        k(  r	 |j	                  d      }| j                  s| j                  d= | j                  s| j                  j                  g        | j                  d   j                  |       dj                  | j                  d         }d}|| j                  |       d| _        n| j                  |      x}| _        t        j                  d| |||       |S # t
        $ r Y w xY w# t        $ r Y w xY w)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
FzInterpreter.push)signalsendercommandr   source)sixPY3typeunicodeencodeUnicodeEncodeErrorr   r   
IndexErrorappendjoin	runModule	runsourcer   send)r    r*   astModr+   r   s        r$   pushzInterpreter.push1   s    wwG}'%nnW5G yy''+yy$,,33B72%%g.4--b12 NN6"DI#~~f55D491$ 'd6	C' * 
 #t#s#   D D 	DD	DDc                    t         j                  t         j                  t         j                  }}}| j                  | j                  | j                  ct         _        t         _        t         _        t	        j
                  | |      }t         j                  | j                  k(  r|t         _        nt         j                  | _        t         j                  | j                  k(  r|t         _        nt         j                  | _        t         j                  | j                  k(  r|t         _        |S t         j                  | _        |S )z/Compile and run source code in the interpreter.)r   r   r   r   r   r6   )r    r+   r   r   r   r   s         r$   r6   zInterpreter.runsourceU   s     #		3::szzvv::t{{DKK 	*	3:sz%//f= 99

"CIDJ::$CJ**DK::$CJ  **DK    c                    t         j                  t         j                  t         j                  }}}| j                  | j                  | j                  ct         _        t         _        t         _        | j	                  t        |dd             t         j                  | j                  k(  r|t         _        nt         j                  | _        t         j                  | j                  k(  r|t         _        nt         j                  | _        t         j                  | j                  k(  r|t         _        yt         j                  | _        y)z1Compile and run an ast module in the interpreter. singleF)r   r   r   r   runcodecompile)r    modr   r   r   s        r$   r5   zInterpreter.runModuleq   s     #		3::szzvv::t{{DKK 	*	3:szWSH-. 99

"CIDJ::$CJ**DK::$CJ  **DKr;   c                     t        d      gS )z(Return list of auto-completion keycodes..)ord)r    s    r$   getAutoCompleteKeyszInterpreter.getAutoCompleteKeys   s    Czr;   c                 r   t         j                  t         j                  t         j                  }}}| j                  | j                  | j                  ct         _        t         _        t         _        t	        j
                  || j                  g|i |}|||c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   ls           r$   rG   zInterpreter.getAutoCompleteList   s     !$		3::szzvv::t{{DKK 	*	3:sz**7DKK :,0:48:,166)	3:szr;   c                 J    t        j                  || j                  g|i |S )zhReturn call tip text for a command.

        Call tip information will be based on the locals namespace.)r   
getCallTipr   )r    r*   rH   rI   s       r$   rL   zInterpreter.getCallTip   s%     $$WdkkIDIDIIr;   )N)r=   )__name__
__module____qualname____doc__r   r   r   r   r   r9   r6   r5   rE   rG   rL    r;   r$   r	   r	      sG    ; #$yyCJJ!%"<"H8.
Jr;   r	   c                       e Zd ZdZ	 ddZy)InterpreterAlaCartezDemo Interpreter.c                 f    t         j                  | |||||       |t        _        |t        _        y)r   )r   r!   r   r   r   N)r	   r   r   r   r   )r    r   r!   r   r   r   r   r   s           r$   r   zInterpreterAlaCarte.__init__   s3     	T&#( 	 	Hr;   N)zmain promptzcontinuation prompt)rM   rN   rO   rP   r   rQ   r;   r$   rS   rS      s     )>r;   rS   )rP   
__author__r   r   coder   r   r=   r   r   wxr,   r	   rS   rQ   r;   r$   <module>rX      sM    +:
 
> >
 
 
 8   	 
MJ( MJ`	+ 	r;   