Examples of PyObject


Examples of org.python.core.PyObject

    _interpreter = new PythonInterpreter();
    _interpreter.exec("import sys;");
    _interpreter.exec("sys.path.append('" + new File("lib").getAbsolutePath() + "')");
    _interpreter.exec("sys.path.append('" + new File("lib", "external").getAbsolutePath() + "')");
        _interpreter.exec("from " + pythonPackage + " import " + pythonClass);
        PyObject serviceClass = _interpreter.get(pythonClass);
        PyObject implObj = serviceClass.__call__();
        _impl = (JavaServiceI)implObj.__tojava__(JavaServiceI.class);
       
        _impl.init(config);
       
        _interpreter.exec("print sys.path");
  }
View Full Code Here

Examples of org.python.core.PyObject

            python.execfile(scriptResource.getInputStream());
        } catch (IOException e) {
            throw new IllegalArgumentException("Couldn't run python script, " + script, e);
        }

        PyObject allowed = python.get("allow");

        if (allowed == null) {
            throw new IllegalStateException("Python script did not set the permit flag");
        }
View Full Code Here

Examples of org.python.core.PyObject

      boolean result = evalPredicate(interp, predicate);
      return result;
    }
   
    protected boolean evalPredicate(PythonInterpreter interp, String predicate) {
      PyObject pyResult = interp.eval(predicate);
      Boolean resultObj = (Boolean) pyResult.__tojava__(Boolean.class);
      boolean result = resultObj.booleanValue();
      return result;
    }
View Full Code Here

Examples of org.python.core.PyObject

            }
            if (message == null) {
                if (pe.type instanceof PyClass) {
                    String errorName = null, errorValue;
                    try {
                        PyObject doc = pe.value.__getattr__(new PyString("__doc__"));
                        if (doc != Py.None) {
                            errorName = doc.toString();
                            if (errorName.endsWith(".")) {
                                errorName = errorName.substring(0, errorName.length() - 1);
                            }
                        }
                    } catch (PyException pye) {
View Full Code Here

Examples of org.python.core.PyObject

    public void setVariable(String name, Object value) throws Exception {
        if (mPySimulator == null) {
            logAndThrowException("Python simulator instance not loaded");
        }
        try {
            PyObject pyValue = (value instanceof PyObject) ? (PyObject) value : Py.java2py(value);
            mPySimulator.__setattr__(new PyString(name), pyValue);
            return;
        } catch (PyException e) {
            logAndThrowException("Error while setting value of " + name + " variable of Python simulator instance", e);
        }
View Full Code Here

Examples of org.python.core.PyObject

    public Object invoke(String method, Object[] arguments) throws Exception {
        if (mPySimulator == null) {
            logAndThrowException("Python simulator instance not loaded");
        }
        try {
            PyObject pyMethod = mPySimulator.__getattr__(new PyString(method));
            return pyMethod._jcall(arguments);
        } catch (PyException e) {
            logAndThrowException("Error while invoking " + method + " method of Python simulator instance", e);
        }
        return null; // not executed
    }
View Full Code Here

Examples of org.python.core.PyObject

    @Override public SearchScript search(Object compiledScript, SearchLookup lookup, @Nullable Map<String, Object> vars) {
        return new PythonSearchScript((PyCode) compiledScript, vars, lookup);
    }

    @Override public Object execute(Object compiledScript, Map<String, Object> vars) {
        PyObject pyVars = Py.java2py(vars);
        interp.setLocals(pyVars);
        PyObject ret = interp.eval((PyCode) compiledScript);
        if (ret == null) {
            return null;
        }
        return ret.__tojava__(Object.class);
    }
View Full Code Here

Examples of org.python.core.PyObject

            pyVars.__setitem__(name, Py.java2py(value));
        }

        @Override public Object run() {
            interp.setLocals(pyVars);
            PyObject ret = interp.eval(code);
            if (ret == null) {
                return null;
            }
            return ret.__tojava__(Object.class);
        }
View Full Code Here

Examples of org.python.core.PyObject

            pyVars.__setitem__(name, Py.java2py(value));
        }

        @Override public Object run() {
            interp.setLocals(pyVars);
            PyObject ret = interp.eval(code);
            if (ret == null) {
                return null;
            }
            return ret.__tojava__(Object.class);
        }
View Full Code Here

Examples of org.python.core.PyObject

  }

  protected Object get(String name) {
    //Bug 2208873: Don't use _ip.get(String, Object) since it
    //doesn't handle null well
    PyObject val = _ip.get(name);
    return val != null ? Py.tojava(val, Object.class): null;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.