Search in sources :

Example 1 with PyException

use of org.python.core.PyException in project oxCore by GluuFederation.

the class PythonService method initPythonInterpreter.

/*
	 * Initialize singleton instance during startup
	 */
public boolean initPythonInterpreter(String pythonModulesDir) {
    boolean result = false;
    if (isInitInterpreter()) {
        try {
            PythonInterpreter.initialize(getPreProperties(), getPostProperties(pythonModulesDir), null);
            this.pythonInterpreter = new PythonInterpreter();
            // Init output redirect for all new interpreters
            this.pythonInterpreter.setOut(new PythonLoggerOutputStream(log, false));
            this.pythonInterpreter.setErr(new PythonLoggerOutputStream(log, true));
            result = true;
        } catch (PyException ex) {
            log.error("Failed to initialize PythonInterpreter correctly", ex);
        } catch (Exception ex) {
            log.error("Failed to initialize PythonInterpreter correctly", ex);
        }
    }
    this.interpereterReady = result;
    return result;
}
Also used : PythonInterpreter(org.python.util.PythonInterpreter) PyException(org.python.core.PyException) PythonException(org.xdi.exception.PythonException) IOException(java.io.IOException) PyException(org.python.core.PyException)

Example 2 with PyException

use of org.python.core.PyException in project scriptographer by scriptographer.

the class JythonCallable method call.

public Object call(Object obj, Object[] args) throws JythonException {
    // function on it.
    try {
        PyObject[] wrappedArgs = new PyObject[args == null ? 1 : args.length + 1];
        // self
        wrappedArgs[0] = Py.java2py(obj);
        // args
        for (int i = 1; i < wrappedArgs.length; i++) wrappedArgs[i] = Py.java2py(args[i - 1]);
        PyObject ret = function.__call__(wrappedArgs);
        // unwrap if the return value is a native java object:
        Object res = ret.__tojava__(Object.class);
        return res != Py.NoConversion ? res : ret;
    } catch (PyException e) {
        throw new JythonException(e);
    }
}
Also used : PyException(org.python.core.PyException) PyObject(org.python.core.PyObject) PyObject(org.python.core.PyObject)

Aggregations

PyException (org.python.core.PyException)2 IOException (java.io.IOException)1 PyObject (org.python.core.PyObject)1 PythonInterpreter (org.python.util.PythonInterpreter)1 PythonException (org.xdi.exception.PythonException)1