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 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);
}
}
use of org.python.core.PyObject in project apex-malhar by apache.
the class PythonOperator method getBindings.
@Override
public Map<String, Object> getBindings() {
Map<String, Object> bindings = new HashMap<String, Object>();
PyStringMap keyValueMap = (PyStringMap) interp.getLocals();
PyIterator keyValueSet = (PyIterator) keyValueMap.iteritems();
for (Object temp : keyValueSet) {
PyTuple tempEntry = (PyTuple) temp;
Iterator<PyObject> iter = tempEntry.iterator();
bindings.put((String) iter.next().__tojava__(String.class), iter.next());
}
return bindings;
}
use of org.python.core.PyObject in project cucumber-jvm by cucumber.
the class JythonStepDefinition method matchedArguments.
@Override
public List<Argument> matchedArguments(Step step) {
PyObject stepName = new PyString(step.getName());
PyObject matched_arguments = stepdef.invoke("matched_arguments", stepName);
if (matched_arguments instanceof PyList) {
return (PyList) matched_arguments;
} else {
return null;
}
}
use of org.python.core.PyObject in project OpenRefine by OpenRefine.
the class JythonHasFieldsWrapper method __finditem__.
@Override
public PyObject __finditem__(PyObject key) {
String k = (String) key.__tojava__(String.class);
Object v = _obj.getField(k, _bindings);
if (v != null) {
if (v instanceof PyObject) {
return (PyObject) v;
} else if (v instanceof HasFields) {
return new JythonHasFieldsWrapper((HasFields) v, _bindings);
} else if (Py.getAdapter().canAdapt(v)) {
return Py.java2py(v);
} else {
return new JythonObjectWrapper(v);
}
} else {
return null;
}
}
Aggregations