class SXPy {

    Method mJava2py = null;

    public SXPy() {
      try {
        mJava2py = Class.forName("org.python.core.Py").getMethod("java2py", Object.class);
      } catch (Exception ex) {
      }
    }
    Object java2py(Object arg) {
      if (mJava2py == null) {
        return null;
      }
      Object pyObject = null;
      try {
        pyObject = mJava2py.invoke(null, arg);
      } catch (Exception ex) {
      }
      return pyObject;
    }
  }
  //</editor-fold>

  //<editor-fold desc="17 exec/eval">
  public Object interpreterEval(String expression) {
    if (interpreter == null) {
      return "";
    }
    return interpreter.eval(expression);
  }

  public boolean interpreterExecString(String script) {
    interpreter.exec(script);
    return true;
  }

  public void interpreterExecCode(File compiledScript) {
    String scriptFile = compiledScript.getAbsolutePath();
    byte[] data = new byte[0];
    try {
      data = FileUtils.readFileToByteArray(compiledScript);
    } catch (IOException e) {
      log(-1, "exec compiled script: %s", e.getMessage());
    }
    PyCode pyCode = BytecodeLoader.makeCode(FilenameUtils.getBaseName(scriptFile), data, scriptFile);
    interpreter.exec(pyCode);
  }

  public void interpreterExecFile(String script) {
    interpreter.execfile(script);
  }

  public void executeScriptHeader(List<String> codeBefore) {
//    Debug.on(4);
    for (String line : SCRIPT_HEADER) {
      log(lvl + 1, "executeScriptHeader: %s", line);
      interpreterExecString(line);
    }
    if (codeBefore != null) {
      for (String line : codeBefore) {
        interpreterExecString(line);
      }
    }
  }

  /**
   * The header commands, that are executed before every script
   */
  private static String[] SCRIPT_HEADER = new String[]{
          "# -*- coding: utf-8 -*- ",
          "import time; start = time.time()",
          "from sikuli import *",
          "resetBeforeScriptStart()",
          "Debug.log(3, 'Jython: BeforeScript: %s (%f)',  SCREEN, time.time()-start)",
  };
  //</editor-fold>

  //<editor-fold desc="10 sys.path handling">
  List<String> sysPath = new ArrayList<String>();
  int nPathAdded = 0;
  int nPathSaved = -1;
  private List<File> importedScripts = new ArrayList<File>();
  String name = "";
  private long lastRun = 0;

  public void getSysPath() {
    synchronized (sysPath) {
      if (null == interpreter) {
        return;
      }
      sysPath.clear();
      try {
        PySystemState pyState = interpreter.getSystemState();
        PyList pyPath = pyState.path;
        int pathLen = pyPath.__len__();
        for (int i = 0; i < pathLen; i++) {
          String entry = (String) pyPath.get(i);
          log(lvl + 1, "sys.path[%2d] = %s", i, entry);
          sysPath.add(entry);
        }
      } catch (Exception ex) {
        sysPath.clear();
      }
    }
  }

  public void setSysPath() {<FILL_FUNCTION_BODY>

    synchronized (sysPath) {
      if (null == interpreter || null == sysPath) {
        return;
      }
      try {
        PySystemState pyState = interpreter.getSystemState();
        PyList pyPath = pyState.path;
        int pathLen = pyPath.__len__();
        for (int i = 0; i < pathLen && i < sysPath.size(); i++) {
          String entry = sysPath.get(i);
          log(lvl + 1, "sys.path.set[%2d] = %s", i, entry);
          pyPath.set(i, entry);
        }
        if (pathLen < sysPath.size()) {
          for (int i = pathLen; i < sysPath.size(); i++) {
            String entry = sysPath.get(i);
            log(lvl + 1, "sys.path.add[%2d] = %s", i, entry);
            pyPath.add(entry);
          }
        }
        if (pathLen > sysPath.size()) {
          for (int i = sysPath.size(); i < pathLen; i++) {
            String entry = (String) pyPath.get(i);
            log(lvl + 1, "sys.path.rem[%2d] = %s", i, entry);
            pyPath.remove(i);
          }
        }
      } catch (Exception ex) {
        sysPath.clear();
      }
    }
  
<no_super_class>