Class Interpreter

java.lang.Object
org.python.util.PythonInterpreter
org.python.util.InteractiveInterpreter
edu.wisc.ssec.mcidasv.jython.Interpreter
All Implemented Interfaces:
Closeable, AutoCloseable

public class Interpreter extends org.python.util.InteractiveInterpreter
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    A hook that allows external classes to respond to events.
    private static final String
    Dummy filename for the interactive interpreter.
    private boolean
    Whether or not jython needs more input to run something.
    Stream used for error output.
    Stream used for normal output.
    private boolean
    Whether or not Jython is working on something

    Fields inherited from class org.python.util.InteractiveInterpreter

    buffer, filename

    Fields inherited from class org.python.util.PythonInterpreter

    cflags, systemState, threadLocals, useThreadLocalState
  • Constructor Summary

    Constructors
    Constructor
    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.
  • Method Summary

    Modifier and Type
    Method
    Description
    private static String
    Removes and returns all existing text from stream.
    void
    Sends error information to the specified console.
    void
    handleStreams(Console console, String command)
    Sends the contents of stdout and stderr on their merry way.
    boolean
    Determines whether or not Jython is busy.
    boolean
     
    boolean
    push(Console console, String line)
    Here's the magic!
    protected void
    Registers a new callback handler with the interpreter.

    Methods inherited from class org.python.util.InteractiveInterpreter

    interrupt, resetbuffer, runcode, runsource, runsource, runsource, showexception, write

    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, setSystemState, threadLocalStateInterpreter

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • 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

      protected void setCallbackHandler(ConsoleCallback newCallback)
      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

      public boolean push(Console console, String line)
      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

      public boolean isBusy()
      Determines whether or not Jython is busy.
      Returns:
      true if busy, false otherwise.
    • needMoreInput

      public boolean needMoreInput()
      Returns:
      Whether or not Jython needs more input to run something.
    • handleStreams

      public void handleStreams(Console console, String command)
      Sends the contents of stdout and stderr on their merry way. Both streams are emptied as a result.
      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

      private static String clearStream(String command, ByteArrayOutputStream stream)
      Removes and returns all existing text from stream.
      Parameters:
      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.
      Returns:
      The contents of stream before it was reset.
      See Also:
    • handleException

      public void handleException(Console console, Throwable e)
      Sends error information to the specified console.
      Parameters:
      console - The console that caused the exception.
      e - The exception!