use of org.python.core.PyObject in project score by CloudSlang.
the class EmbeddedPythonExecutorWrapper method doEval.
private Serializable doEval(String prepareEnvironmentScript, String script) {
// Set boolean values
pythonInterpreter.set("true", Boolean.TRUE);
pythonInterpreter.set("false", Boolean.FALSE);
// Prepare environment if required
if (isNotEmpty(prepareEnvironmentScript)) {
pythonInterpreter.exec(prepareEnvironmentScript);
}
PyObject evalResultPyObject = pythonInterpreter.eval(script);
return resolveJythonObjectToJavaForEval(evalResultPyObject, script);
}
use of org.python.core.PyObject in project score by CloudSlang.
the class EmbeddedPythonExecutorWrapper method processExecResults.
private PythonExecutionResult processExecResults() {
Iterator<PyObject> localsIterator = pythonInterpreter.getLocals().asIterable().iterator();
Map<String, Serializable> returnValue = new HashMap<>();
while (localsIterator.hasNext()) {
PyObject next = localsIterator.next();
String key = next.asString();
PyObject value = pythonInterpreter.get(key);
if (!isLocalEntryExcluded(key, value)) {
returnValue.put(key, resolveJythonObjectToJavaForExec(value, key));
}
}
return new PythonExecutionResult(returnValue);
}
use of org.python.core.PyObject in project MeteoInfo by meteoinfo.
the class FrmMain method loadApplication.
/**
* Load an application
*
* @param plugin Application
*/
public void loadApplication(Application plugin) {
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try {
PythonInterpreter interp = this.getConsoleDockable().getInterpreter();
String path = plugin.getPath();
interp.exec("import " + path);
interp.exec("from " + path + ".loadApp import LoadApp");
PyObject loadClass = interp.get("LoadApp");
PyObject loadObj = loadClass.__call__();
IPlugin instance = (IPlugin) loadObj.__tojava__(IPlugin.class);
instance.setApplication(FrmMain.this);
instance.setName(plugin.getName());
plugin.setPluginObject(instance);
plugin.setLoad(true);
instance.load();
} catch (Exception e) {
e.printStackTrace();
}
this.setCursor(Cursor.getDefaultCursor());
}
use of org.python.core.PyObject in project MeteoInfo by meteoinfo.
the class FrmAppsManager method readPyApp.
// GEN-LAST:event_formWindowClosed
public Application readPyApp(String path, String fileName) {
try {
Application plugin = new Application();
plugin.setPath(path);
plugin.setClassName("LoadApp");
PythonInterpreter interp = this.parent.getConsoleDockable().getInterpreter();
interp.exec("import " + path);
interp.exec("from " + path + ".loadApp import LoadApp");
PyObject loadClass = interp.get("LoadApp");
PyObject loadObj = loadClass.__call__();
IPlugin instance = (IPlugin) loadObj.__tojava__(IPlugin.class);
plugin.setPluginObject(instance);
return plugin;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of org.python.core.PyObject in project scisoft-core by DawnScience.
the class PythonUtilsTest method testCompile.
private void testCompile(boolean isSingle) throws Exception {
// NB "eval" is not available in Jython nor documented in CPython
CompileMode mode = isSingle ? CompileMode.single : CompileMode.exec;
String filename = "<input>";
CompilerFlags flags = new CompilerFlags();
PyObject ret = Py.compile_command_flags("", filename, mode, flags, false);
System.out.println(ret);
ret = Py.compile_command_flags("1", filename, mode, flags, false);
System.out.println(ret);
ret = Py.compile_command_flags("print 2", filename, mode, flags, false);
System.out.println(ret);
ret = Py.compile_command_flags("if True: print 42", filename, mode, flags, false);
if (isSingle) {
assertEquals(Py.None, ret);
}
System.out.println(ret);
try {
ret = Py.compile_command_flags("if True:", filename, mode, flags, false);
if (isSingle) {
assertEquals(Py.None, ret);
} else {
fail();
}
System.out.println(ret);
} catch (Exception e) {
}
}
Aggregations