public class InteractiveConsole extends InteractiveInterpreter
interact()
method, which repeatedly
calls raw_input(PyObject)
, and hence __builtin__.raw_input(PyObject)
, in order
to get lines, and push(String)
them into the interpreter. The built-in
raw_input()
method prompts on sys.stdout
and reads from
sys.stdin
, the standard console. These may be redirected using
PythonInterpreter.setOut(java.io.OutputStream)
and PythonInterpreter.setIn(java.io.InputStream)
, as may also
sys.stderr
.Modifier and Type | Field and Description |
---|---|
static String |
CONSOLE_FILENAME |
String |
filename |
buffer
Constructor and Description |
---|
InteractiveConsole()
Construct an interactive console, which will "run" when
interact() is called. |
InteractiveConsole(PyObject locals)
Construct an interactive console, which will "run" when
interact() is called. |
InteractiveConsole(PyObject locals,
String filename)
Construct an interactive console, which will "run" when
interact() is called. |
InteractiveConsole(PyObject locals,
String filename,
boolean replaceRawInput)
Full-feature constructor for an interactive console, which will "run" when
interact() is called. |
Modifier and Type | Method and Description |
---|---|
static String |
getDefaultBanner()
Returns the banner to print before the first interaction: "Jython
|
void |
interact()
Operate a Python console, as in
interact(String, PyObject) , on the standard input. |
void |
interact(String banner,
PyObject file)
Operate a Python console by repeatedly calling
raw_input(PyObject, PyObject) and
interpreting the lines read. |
boolean |
push(String line)
Push a line to the interpreter.
|
String |
raw_input(PyObject prompt)
Write a prompt and read a line from standard input.
|
String |
raw_input(PyObject prompt,
PyObject file)
Write a prompt and read a line from a file.
|
interrupt, resetbuffer, runcode, runsource, runsource, runsource, showexception, write
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 static final String CONSOLE_FILENAME
public String filename
public InteractiveConsole()
interact()
is called. The
name of the console (e.g. in error messages) will be "<stdin>".public InteractiveConsole(PyObject locals)
interact()
is called. The
name of the console (e.g. in error messages) will be "<stdin>".locals
- dictionary to use, or if null
, a new empty one will be createdpublic InteractiveConsole(PyObject locals, String filename)
interact()
is called.locals
- dictionary to use, or if null
, a new empty one will be createdfilename
- name with which to label this console input (e.g. in error messages).public InteractiveConsole(PyObject locals, String filename, boolean replaceRawInput)
interact()
is called. This version allows the caller to replace the built-in
raw_input() methods with raw_input(PyObject)
and
raw_input(PyObject, PyObject)
, which may be overridden in a sub-class.locals
- dictionary to use, or if null
, a new empty one will be createdfilename
- name with which to label this console inputreplaceRawInput
- if true, hook this class's raw_input
into the built-ins.public void interact()
interact(String, PyObject)
, on the standard input.
The standard input may have been redirected by PythonInterpreter.setIn(java.io.InputStream)
or its
variants. The banner (printed before first input) is obtained by calling
getDefaultBanner()
.public static String getDefaultBanner()
public void interact(String banner, PyObject file)
raw_input(PyObject, PyObject)
and
interpreting the lines read. An end of file causes the method to return.banner
- to print before accepting input, or if null
, no banner.file
- from which to read commands, or if null
, read the console.public boolean push(String line)
public String raw_input(PyObject prompt)