Top Description Fields Constructors Methods
org.python.util

public Class InteractiveInterpreter

Additional top-level class in compilation unit: BreakTraceFunction.

extends PythonInterpreter
Class Inheritance
Known Direct Subclasses
org.python.util.InteractiveConsole
Imports
org.python.core.*

This class provides the interface for compiling and running code that supports an interactive interpreter.

Field Summary

Modifier and TypeField and Description
public StringBuilder
public String
Inherited from org.python.util.PythonInterpreter:
cflagsglobalssystemStatethreadLocalsuseThreadLocalState

Constructor Summary

AccessConstructor and Description
public
InteractiveInterpreter()

Construct an InteractiveInterpreter with all default characteristics: default state (from Py#getSystemState()), and a new empty dictionary of local variables.

public
InteractiveInterpreter(PyObject
dictionary to use, or if null, a new empty one will be created
locals
)

Construct an InteractiveInterpreter with state (from Py#getSystemState()), and the specified dictionary of local variables.

public
InteractiveInterpreter(PyObject
dictionary to use, or if null, a new empty one will be created
locals
,
PySystemState
interpreter state, or if null use Py#getSystemState()
systemState
)

Construct an InteractiveInterpreter with, and system state the specified dictionary of local variables.

Method Summary

Modifier and TypeMethod and Description
public void
interrupt(ThreadState ts)

Pause the current code, sneak an exception raiser into sys.trace_func, and then continue the code hoping that Jython will get control to do the break;

public void
public void
runcode(PyObject code)

Execute a code object.

public boolean

Returns:

true to indicate a partial statement was entered
runsource
(String
Python code
source
)

Compile and run some source in the interpreter, in the mode CompileMode#single which is used for incremental compilation at the interactive console, known as <input>.

public boolean

Returns:

true to indicate a partial statement was entered
runsource
(String
Python code
source
,
String
name with which to label this console input (e.g. in error messages).
filename
)

Compile and run some source in the interpreter, in the mode CompileMode#single which is used for incremental compilation at the interactive console.

public boolean

Returns:

true to indicate a partial statement was provided
runsource
(String
Python code
source
,
String
name with which to label this console input (e.g. in error messages).
filename
,
CompileMode kind)

Compile and run some source in the interpreter, according to the CompileMode given.

public void
public void
write(String data)

Inherited from org.python.util.PythonInterpreter:
cleanupclosecompilecompilecompilecompileevalevalexecexecexecfileexecfileexecfilegetgetgetLocalsgetSystemStateinitializesetsetsetErrsetErrsetErrsetInsetInsetInsetLocalssetOutsetOutsetOutsetSystemStatethreadLocalStateInterpreter

Field Detail

bufferback to summary
public StringBuilder buffer
filenameback to summary
public String filename

Constructor Detail

InteractiveInterpreterback to summary
public InteractiveInterpreter()

Construct an InteractiveInterpreter with all default characteristics: default state (from Py#getSystemState()), and a new empty dictionary of local variables.

InteractiveInterpreterback to summary
public InteractiveInterpreter(PyObject locals)

Construct an InteractiveInterpreter with state (from Py#getSystemState()), and the specified dictionary of local variables.

Parameters
locals:PyObject

dictionary to use, or if null, a new empty one will be created

InteractiveInterpreterback to summary
public InteractiveInterpreter(PyObject locals, PySystemState systemState)

Construct an InteractiveInterpreter with, and system state the specified dictionary of local variables.

Parameters
locals:PyObject

dictionary to use, or if null, a new empty one will be created

systemState:PySystemState

interpreter state, or if null use Py#getSystemState()

Method Detail

interruptback to summary
public void interrupt(ThreadState ts)

Pause the current code, sneak an exception raiser into sys.trace_func, and then continue the code hoping that Jython will get control to do the break;

resetbufferback to summary
public void resetbuffer()
runcodeback to summary
public void runcode(PyObject code)

Execute a code object. When an exception occurs, showexception(PyException) is called to display a stack trace, except in the case of SystemExit, which is re-raised.

A note about KeyboardInterrupt: this exception may occur elsewhere in this code, and may not always be caught. The caller should be prepared to deal with it.

runsourceback to summary
public boolean runsource(String source)

Compile and run some source in the interpreter, in the mode CompileMode#single which is used for incremental compilation at the interactive console, known as <input>.

Parameters
source:String

Python code

Returns:boolean

true to indicate a partial statement was entered

runsourceback to summary
public boolean runsource(String source, String filename)

Compile and run some source in the interpreter, in the mode CompileMode#single which is used for incremental compilation at the interactive console.

Parameters
source:String

Python code

filename:String

name with which to label this console input (e.g. in error messages).

Returns:boolean

true to indicate a partial statement was entered

runsourceback to summary
public boolean runsource(String source, String filename, CompileMode kind)

Compile and run some source in the interpreter, according to the CompileMode given. This method supports incremental compilation and interpretation through the return value, where true signifies that more input is expected in order to complete the Python statement. An interpreter can use this to decide whether to use sys.ps1 (">>> ") or sys.ps2 ("... ") to prompt the next line. The arguments are the same as the mandatory ones in the Python compile() command.

One the following can happen:

  1. The input is incorrect; compilation raised an exception (SyntaxError or OverflowError). A syntax traceback will be printed by calling showexception(PyException). Return is false.
  2. The input is incomplete, and more input is required; compilation returned no code. Nothing happens. Return is true.
  3. The input is complete; compilation returned a code object. The code is executed by calling runcode(PyObject) (which also handles run-time exceptions, except for SystemExit). Return is false.
Parameters
source:String

Python code

filename:String

name with which to label this console input (e.g. in error messages).

kind:CompileMode

of compilation required: CompileMode#eval, CompileMode#exec or CompileMode#single

Returns:boolean

true to indicate a partial statement was provided

showexceptionback to summary
public void showexception(PyException exc)
writeback to summary
public void write(String data)