use of org.python.core.PyObject in project Pydev by fabioz.
the class JythonPep8 method analyzePep8WithJython.
public static void analyzePep8WithJython(JythonPep8Core pep8Params) {
FastStringBuffer args = new FastStringBuffer(pep8Params.pep8CommandLine.length * 20);
for (String string : pep8Params.pep8CommandLine) {
args.append(',').append("r'").append(string).append('\'');
}
// It's important that the interpreter is created in the Thread and not outside the thread (otherwise
// it may be that the output ends up being shared, which is not what we want.)
IPythonInterpreter interpreter = JythonPlugin.newPythonInterpreter(pep8Params.useConsole, false);
String file = StringUtils.replaceAllSlashes(pep8Params.absolutePath);
interpreter.set("visitor", pep8Params.visitor);
List<String> splitInLines = StringUtils.splitInLines(pep8Params.document.get());
interpreter.set("lines", splitInLines);
PyObject tempReportError = reportError;
if (tempReportError != null) {
interpreter.set("ReportError", tempReportError);
} else {
interpreter.set("ReportError", Py.None);
}
PyObject pep8Module = JythonModules.getPep8Module(interpreter);
interpreter.set("pycodestyle", pep8Module);
String formatted = StringUtils.format(EXECUTE_PEP8, file, args.toString(), file);
interpreter.exec(formatted);
if (reportError == null) {
synchronized (lock) {
if (reportError == null) {
reportError = (PyObject) interpreter.get("ReportError");
}
}
}
}
use of org.python.core.PyObject in project score by CloudSlang.
the class EmbeddedPythonExecutorWrapper method getPythonLocals.
private Map<String, Serializable> getPythonLocals() {
Map<String, Serializable> retVal = new HashMap<>();
for (PyObject pyObject : pythonInterpreter.getLocals().asIterable()) {
String key = pyObject.asString();
PyObject value = pythonInterpreter.get(key);
if (!isLocalEntryExcluded(key, value)) {
retVal.put(key, value);
}
}
return retVal;
}
use of org.python.core.PyObject in project score by CloudSlang.
the class PythonExecutor method getPythonLocals.
private Map<String, Serializable> getPythonLocals() {
Map<String, Serializable> result = new HashMap<>();
if (interpreter.getLocals() != null) {
for (PyObject pyObject : interpreter.getLocals().asIterable()) {
String key = pyObject.asString();
PyObject value = interpreter.get(key);
if (keyIsExcluded(key, value)) {
continue;
}
result.put(key, value);
}
}
return result;
}
use of org.python.core.PyObject in project score by CloudSlang.
the class PythonExecutor method eval.
protected Serializable eval(String prepareEnvironmentScript, String script) {
if (interpreter.get(TRUE) == null) {
interpreter.set(TRUE, Boolean.TRUE);
}
if (interpreter.get(FALSE) == null) {
interpreter.set(FALSE, Boolean.FALSE);
}
if (prepareEnvironmentScript != null && !prepareEnvironmentScript.isEmpty()) {
interpreter.exec(prepareEnvironmentScript);
}
PyObject evalResultAsPyObject = interpreter.eval(script);
Serializable evalResult;
evalResult = resolveJythonObjectToJavaEval(evalResultAsPyObject, script);
return evalResult;
}
use of org.python.core.PyObject in project score by CloudSlang.
the class PythonExecutor method exec.
private PythonExecutionResult exec(String script) {
interpreter.exec(script);
Iterator<PyObject> localsIterator = interpreter.getLocals().asIterable().iterator();
Map<String, Serializable> returnValue = new HashMap<>();
while (localsIterator.hasNext()) {
String key = localsIterator.next().asString();
PyObject value = interpreter.get(key);
if (keyIsExcluded(key, value)) {
continue;
}
Serializable javaValue = resolveJythonObjectToJavaExec(value, key);
returnValue.put(key, javaValue);
}
return new PythonExecutionResult(returnValue);
}
Aggregations