Package ghidra.jython

# Class GhidraJythonInterpreter

java.lang.Object
org.python.util.PythonInterpreter
org.python.util.InteractiveInterpreter
ghidra.jython.GhidraJythonInterpreter

All Implemented Interfaces:
  `Closeable`, `AutoCloseable`

public class GhidraJythonInterpreter extends org.python.util.InteractiveInterpreter
A python interpreter meant for Ghidra's use. Each interpreter you get will have its own variable space so they should not interfere with each other.

There is no longer a way to reset an interpreter...it was too complicated to get right. Instead, you should `cleanup()` your old interpreter and make a new one.

- ## Field Summary

  ### Fields inherited from class org.python.util.InteractiveInterpreter

  `buffer, filename`

  ### Fields inherited from class org.python.util.PythonInterpreter

  `cflags, systemState, threadLocals, useThreadLocalState`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `cleanup()`
  `void`
  `clearLocals()`
  Clears the interpreter's locals
  `void`
  `execFile(ResourceFile file, JythonScript script)`
  Execute a python file using this interpreter.
  `static GhidraJythonInterpreter`
  `get()`
  Gets a new GhidraPythonInterpreter instance.
  `boolean`
  `push(String line, JythonScript script)`
  Pushes (executes) a line of Python to the interpreter.
  `void`
  `restoreLocals()`
  Restores the locals that were last saved with the `saveLocals()` method, and removes them from the stack.
  `void`
  `saveLocals()`
  Saves the interpreter's locals to a stack.

  ### Methods inherited from class org.python.util.InteractiveInterpreter

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

  ### Methods inherited from class org.python.util.PythonInterpreter

  `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`

- ## Method Details

  - ### get

    public static GhidraJythonInterpreter get()
    Gets a new GhidraPythonInterpreter instance.
    Returns:
      A new GhidraPythonInterpreter. Could be null if it failed to be created.

  - ### push

    public boolean push(String line, JythonScript script) throws org.python.core.PyException, IllegalStateException
    Pushes (executes) a line of Python to the interpreter.
    Parameters:
      `line` - the line of Python to push to the interpreter
      `script` - a PythonScript from which we load state (or null)
    Returns:
      true if more input is needed before execution can occur
    Throws:
      `org.python.core.PyException` - if an unhandled exception occurred while executing the line of python
      `IllegalStateException` - if this interpreter has been cleaned up.

  - ### execFile

    public void execFile(ResourceFile file, JythonScript script) throws IllegalStateException
    Execute a python file using this interpreter.
    Parameters:
      `file` - The python file to execute.
      `script` - A PythonScript from which we load state (or null).
    Throws:
      `IllegalStateException` - if this interpreter has been cleaned up.

  - ### cleanup

    public void cleanup()
    Overrides:
      `cleanup` in class `org.python.util.PythonInterpreter`

  - ### saveLocals

    public void saveLocals()
    Saves the interpreter's locals to a stack. These locals can be restored with the `restoreLocals()` method.

  - ### clearLocals

    public void clearLocals()
    Clears the interpreter's locals

  - ### restoreLocals

    public void restoreLocals()
    Restores the locals that were last saved with the `saveLocals()` method, and removes them from the stack.