use of org.python.core.PyList in project components by Talend.
the class PythonRowDoFn method flatMap.
private void flatMap(IndexedRecord input, ProcessContext context) throws IOException {
// Prepare Python environment
PyObject outputList = pyFn.__call__(new PyString(input.toString()));
if (outputList instanceof PyList) {
PyList list = (PyList) outputList;
for (Object output : list) {
if (jsonGenericRecordConverter == null) {
JsonSchemaInferrer jsonSchemaInferrer = new JsonSchemaInferrer(new ObjectMapper());
Schema jsonSchema = jsonSchemaInferrer.inferSchema(output.toString());
jsonGenericRecordConverter = new JsonGenericRecordConverter(jsonSchema);
}
GenericRecord outputRecord = jsonGenericRecordConverter.convertToAvro(output.toString());
context.output(outputRecord);
}
}
}
use of org.python.core.PyList 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.PyList 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.PyList in project cucumber-jvm by cucumber.
the class JythonBackend method dataTableToPyArray.
private PyObject dataTableToPyArray(DataTable table) {
PyList pyTable = new PyList();
for (List<String> row : table.raw()) {
PyList pyRow = new PyList();
for (String cell : row) {
pyRow.append(new PyString(cell));
}
pyTable.append(pyRow);
}
return pyTable;
}
use of org.python.core.PyList in project org.csstudio.display.builder by kasemir.
the class JythonScriptSupport method addToPythonPath.
/**
* @param path Path to add to head of python search path
*/
private void addToPythonPath(final String path) {
// Since using default PySystemState (see above), check if already in paths
final PyList paths = python.getSystemState().path;
// Prevent concurrent modification
synchronized (JythonScriptSupport.class) {
final int index = paths.indexOf(path);
// Already top entry?
if (index == 0)
return;
// Remove if further down in the list
if (index > 0)
paths.remove(index);
// Add to front of list
paths.add(0, path);
}
logger.log(Level.FINE, "Adding to jython path: {0}", path);
}
Aggregations