public class Interpreter extends org.python.util.InteractiveInterpreter
Modifier and Type | Field and Description |
---|---|
private ConsoleCallback |
callback
A hook that allows external classes to respond to events.
|
private static String |
CONSOLE_FILENAME
Dummy filename for the interactive interpreter.
|
private boolean |
moreInput
Whether or not jython needs more input to run something.
|
private ByteArrayOutputStream |
stderr
Stream used for error output.
|
private ByteArrayOutputStream |
stdout
Stream used for normal output.
|
private boolean |
thinking
Whether or not Jython is working on something
|
Constructor and Description |
---|
Interpreter(org.python.core.PySystemState state,
ByteArrayOutputStream standardOut,
ByteArrayOutputStream standardError)
Creates a Jython interpreter based upon the specified system state and
whose output streams are mapped to the specified byte streams.
|
Modifier and Type | Method and Description |
---|---|
private static String |
clearStream(String command,
ByteArrayOutputStream stream)
Removes and returns all existing text from
stream . |
void |
handleException(Console console,
Throwable e)
Sends error information to the specified console.
|
void |
handleStreams(Console console,
String command)
|
boolean |
isBusy()
Determines whether or not Jython is busy.
|
boolean |
needMoreInput() |
boolean |
push(Console console,
String line)
Here's the magic!
|
protected void |
setCallbackHandler(ConsoleCallback newCallback)
Registers a new callback handler with the interpreter.
|
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, setSystemState, threadLocalStateInterpreter
private static final String CONSOLE_FILENAME
private ByteArrayOutputStream stderr
private ByteArrayOutputStream stdout
private boolean moreInput
private ConsoleCallback callback
private boolean thinking
public Interpreter(org.python.core.PySystemState state, ByteArrayOutputStream standardOut, ByteArrayOutputStream standardError)
Additionally, the "__main__" module is imported by default so that the locals namespace makes sense.
state
- The system state you want to use with the interpreter.standardOut
- The stream Jython will use for standard output.standardError
- The stream Jython will use for error output.protected void setCallbackHandler(ConsoleCallback newCallback)
newCallback
- The new callback handler.public boolean push(Console console, String line)
line
- A Jython command.public boolean isBusy()
true
if busy, false
otherwise.public boolean needMoreInput()
public void handleStreams(Console console, String command)
console
- Console where the command originated.command
- The command that was executed. Null values are permitted,
as they signify that no command was entered for any generated output.private static String clearStream(String command, ByteArrayOutputStream stream)
stream
.command
- Command that was executed. Null values are permitted and
imply that no command is "associated" with text in
stream
.stream
- Stream to be cleared out.stream
before it was reset.handleStreams(Console, String)
public void handleException(Console console, Throwable e)
console
- The console that caused the exception.e
- The exception!