use of org.python.core.PyTuple in project spring-integration by spring-projects.
the class PythonScriptExecutorTests method test3.
@Test
public void test3() {
ScriptSource source = new ResourceScriptSource(new ClassPathResource("/org/springframework/integration/scripting/jsr223/test3.py"));
Object obj = executor.executeScript(source);
PyTuple tuple = (PyTuple) obj;
assertEquals(1, tuple.get(0));
}
use of org.python.core.PyTuple in project metrics by dropwizard.
the class PickledGraphiteTest method unpickleOutput.
private String unpickleOutput() throws Exception {
StringBuilder results = new StringBuilder();
// the charset is important. if the GraphitePickleReporter and this test
// don't agree, the header is not always correctly unpacked.
String payload = output.toString("UTF-8");
PyList result = new PyList();
int nextIndex = 0;
while (nextIndex < payload.length()) {
Bindings bindings = new SimpleBindings();
bindings.put("payload", payload.substring(nextIndex));
unpickleScript.eval(bindings);
result.addAll(result.size(), (PyList) bindings.get("metrics"));
nextIndex += ((BigInteger) bindings.get("batchLength")).intValue();
}
for (Object aResult : result) {
PyTuple datapoint = (PyTuple) aResult;
String name = datapoint.get(0).toString();
PyTuple valueTuple = (PyTuple) datapoint.get(1);
Object timestamp = valueTuple.get(0);
Object value = valueTuple.get(1);
results.append(name).append(" ").append(value).append(" ").append(timestamp).append("\n");
}
return results.toString();
}
use of org.python.core.PyTuple in project spring-integration by spring-projects.
the class PythonScriptExecutorTests method test3WithVariables.
@Test
public void test3WithVariables() {
ScriptSource source = new ResourceScriptSource(new ClassPathResource("/org/springframework/integration/scripting/jsr223/test3.py"));
HashMap<String, Object> variables = new HashMap<String, Object>();
variables.put("foo", "bar");
Object obj = executor.executeScript(source, variables);
PyTuple tuple = (PyTuple) obj;
assertNotNull(tuple);
assertEquals(1, tuple.get(0));
}
use of org.python.core.PyTuple 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;
}
Aggregations