Package edu.wisc.ssec.mcidasv.jython
Class Interpreter
java.lang.Object
org.python.util.PythonInterpreter
org.python.util.InteractiveInterpreter
edu.wisc.ssec.mcidasv.jython.Interpreter
- All Implemented Interfaces:
Closeable,AutoCloseable
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ConsoleCallbackA hook that allows external classes to respond to events.private static final StringDummy filename for the interactive interpreter.private booleanWhether or not jython needs more input to run something.private ByteArrayOutputStreamStream used for error output.private ByteArrayOutputStreamStream used for normal output.private booleanWhether or not Jython is working on somethingFields inherited from class org.python.util.InteractiveInterpreter
buffer, filenameFields inherited from class org.python.util.PythonInterpreter
cflags, systemState, threadLocals, useThreadLocalState -
Constructor Summary
ConstructorsConstructorDescriptionInterpreter(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. -
Method Summary
Modifier and TypeMethodDescriptionprivate static StringclearStream(String command, ByteArrayOutputStream stream) Removes and returns all existing text fromstream.voidhandleException(Console console, Throwable e) Sends error information to the specified console.voidhandleStreams(Console console, String command) booleanisBusy()Determines whether or not Jython is busy.booleanbooleanHere's the magic!protected voidsetCallbackHandler(ConsoleCallback newCallback) Registers a new callback handler with the interpreter.Methods inherited from class org.python.util.InteractiveInterpreter
interrupt, resetbuffer, runcode, runsource, runsource, runsource, showexception, writeMethods 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, setSystemState, threadLocalStateInterpreter
-
Field Details
-
CONSOLE_FILENAME
Dummy filename for the interactive interpreter.- See Also:
-
stderr
Stream used for error output. -
stdout
Stream used for normal output. -
moreInput
Whether or not jython needs more input to run something. -
callback
A hook that allows external classes to respond to events. -
thinking
Whether or not Jython is working on something
-
-
Constructor Details
-
Interpreter
public 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.Additionally, the "__main__" module is imported by default so that the locals namespace makes sense.
- Parameters:
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.
-
-
Method Details
-
setCallbackHandler
Registers a new callback handler with the interpreter. This mechanism allows external code to easily react to events taking place in the interpreter.- Parameters:
newCallback- The new callback handler.
-
push
Here's the magic! Basically just accumulates a buffer that gets passed off to jython-land until it can run.- Parameters:
line- A Jython command.- Returns:
- False if Jython did something. True if more input is needed.
-
isBusy
Determines whether or not Jython is busy.- Returns:
trueif busy,falseotherwise.
-
needMoreInput
- Returns:
- Whether or not Jython needs more input to run something.
-
handleStreams
- Parameters:
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.
-
clearStream
Removes and returns all existing text fromstream.- Parameters:
command- Command that was executed. Null values are permitted and imply that no command is "associated" with text instream.stream- Stream to be cleared out.- Returns:
- The contents of
streambefore it was reset. - See Also:
-
handleException
Sends error information to the specified console.- Parameters:
console- The console that caused the exception.e- The exception!
-