public class InteractiveInterpreter extends PythonInterpreter
Modifier and Type | Field and Description |
---|---|
java.lang.StringBuilder |
buffer |
java.lang.String |
filename |
Constructor and Description |
---|
InteractiveInterpreter()
Construct an InteractiveInterpreter with all default characteristics: default state (from
Py.getSystemState() ), and a new empty dictionary of local variables. |
InteractiveInterpreter(PyObject locals)
Construct an InteractiveInterpreter with state (from
Py.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.
|
Modifier and Type | Method and Description |
---|---|
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;
|
void |
resetbuffer() |
void |
runcode(PyObject code)
Execute a code object.
|
boolean |
runsource(java.lang.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> . |
boolean |
runsource(java.lang.String source,
java.lang.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. |
boolean |
runsource(java.lang.String source,
java.lang.String filename,
CompileMode kind)
Compile and run some source in the interpreter, according to the
CompileMode given. |
void |
showexception(PyException exc) |
void |
write(java.lang.String data) |
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
public InteractiveInterpreter()
Py.getSystemState()
), and a new empty dictionary of local variables.public InteractiveInterpreter(PyObject locals)
Py.getSystemState()
), and the
specified dictionary of local variables.locals
- dictionary to use, or if null
, a new empty one will be createdpublic InteractiveInterpreter(PyObject locals, PySystemState systemState)
locals
- dictionary to use, or if null
, a new empty one will be createdsystemState
- interpreter state, or if null
use Py.getSystemState()
public boolean runsource(java.lang.String source)
CompileMode.single
which
is used for incremental compilation at the interactive console, known as <input>
.source
- Python codetrue
to indicate a partial statement was enteredpublic boolean runsource(java.lang.String source, java.lang.String filename)
CompileMode.single
which
is used for incremental compilation at the interactive console.source
- Python codefilename
- name with which to label this console input (e.g. in error messages).true
to indicate a partial statement was enteredpublic boolean runsource(java.lang.String source, java.lang.String filename, CompileMode kind)
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:
showexception(PyException)
. Return is
false
.true
.runcode(PyObject)
(which also handles run-time exceptions, except for
SystemExit). Return is false
.source
- Python codefilename
- name with which to label this console input (e.g. in error messages).kind
- of compilation required: CompileMode.eval
, CompileMode.exec
or
CompileMode.single
true
to indicate a partial statement was providedpublic void runcode(PyObject code)
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.
public void showexception(PyException exc)
public void write(java.lang.String data)
public void resetbuffer()
public void interrupt(ThreadState ts)