Package org.python.util
Class InteractiveInterpreter
java.lang.Object
org.python.util.PythonInterpreter
org.python.util.InteractiveInterpreter
- All Implemented Interfaces:
Closeable
,AutoCloseable
- Direct Known Subclasses:
InteractiveConsole
This class provides the interface for compiling and running code that supports an interactive
interpreter.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionConstruct an InteractiveInterpreter with all default characteristics: default state (fromPy.getSystemState()
), and a new empty dictionary of local variables.InteractiveInterpreter
(PyObject locals) Construct an InteractiveInterpreter with state (fromPy.getSystemState()
), and the specified dictionary of local variables.InteractiveInterpreter
(PyObject locals, PySystemState systemState) Construct an InteractiveInterpreter with, and system state the specified dictionary of local variables. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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;void
void
Execute a code object.boolean
Compile and run some source in the interpreter, in the modeCompileMode.single
which is used for incremental compilation at the interactive console, known as<input>
.boolean
Compile and run some source in the interpreter, in the modeCompileMode.single
which is used for incremental compilation at the interactive console.boolean
runsource
(String source, String filename, CompileMode kind) Compile and run some source in the interpreter, according to theCompileMode
given.void
showexception
(PyException exc) void
Methods inherited from class org.python.util.PythonInterpreter
cleanup, close, compile, compile, compile, compile, eval, eval, exec, exec, execfile, execfile, execfile, get, get, getLocals, getSystemState, initialize, set, set, setErr, setErr, setErr, setIn, setIn, setIn, setLocals, setOut, setOut, setOut, threadLocalStateInterpreter
-
Field Details
-
buffer
-
filename
-
-
Constructor Details
-
InteractiveInterpreter
public InteractiveInterpreter()Construct an InteractiveInterpreter with all default characteristics: default state (fromPy.getSystemState()
), and a new empty dictionary of local variables. -
InteractiveInterpreter
Construct an InteractiveInterpreter with state (fromPy.getSystemState()
), and the specified dictionary of local variables.- Parameters:
locals
- dictionary to use, or ifnull
, a new empty one will be created
-
InteractiveInterpreter
Construct an InteractiveInterpreter with, and system state the specified dictionary of local variables.- Parameters:
locals
- dictionary to use, or ifnull
, a new empty one will be createdsystemState
- interpreter state, or ifnull
usePy.getSystemState()
-
-
Method Details
-
runsource
Compile and run some source in the interpreter, in the modeCompileMode.single
which is used for incremental compilation at the interactive console, known as<input>
.- Parameters:
source
- Python code- Returns:
true
to indicate a partial statement was entered
-
runsource
Compile and run some source in the interpreter, in the modeCompileMode.single
which is used for incremental compilation at the interactive console.- Parameters:
source
- Python codefilename
- name with which to label this console input (e.g. in error messages).- Returns:
true
to indicate a partial statement was entered
-
runsource
Compile and run some source in the interpreter, according to theCompileMode
given. This method supports incremental compilation and interpretation through the return value, wheretrue
signifies that more input is expected in order to complete the Python statement. An interpreter can use this to decide whether to usesys.ps1
(">>>
") orsys.ps2
("...
") to prompt the next line. The arguments are the same as the mandatory ones in the Pythoncompile()
command.One the following can happen:
- The input is incorrect; compilation raised an exception (SyntaxError or OverflowError). A
syntax traceback will be printed by calling
showexception(PyException)
. Return isfalse
. - The input is incomplete, and more input is required; compilation returned no code.
Nothing happens. Return is
true
. - 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 isfalse
.
- Parameters:
source
- Python codefilename
- name with which to label this console input (e.g. in error messages).kind
- of compilation required:CompileMode.eval
,CompileMode.exec
orCompileMode.single
- Returns:
true
to indicate a partial statement was provided
- The input is incorrect; compilation raised an exception (SyntaxError or OverflowError). A
syntax traceback will be printed by calling
-
runcode
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.
-
showexception
-
write
-
resetbuffer
public void resetbuffer() -
interrupt
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;
-