public static PyObject eval(PyObject o, PyObject globals, PyObject locals) { verify_mappings(globals, locals); PyCode code; if (o instanceof PyCode) { code = (PyCode) o; } else { if (o instanceof PyString) { code = (PyCode)CompileFunction.compile(o, "<string>", "eval"); } else { throw Py.TypeError("eval: argument 1 must be string or code object"); } } return Py.runCode(code, locals, globals); }
public void execfile(java.io.InputStream s, String name) { setSystemState(); Py.runCode(Py.compile_flags(s, name, CompileMode.exec, cflags), null, getLocals()); Py.flushLine(); }
public static void execfile_flags(String name, PyObject globals, PyObject locals, CompilerFlags cflags) { verify_mappings(globals, locals); FileInputStream file; try { file = new FileInputStream(new RelativeFile(name)); } catch (FileNotFoundException e) { throw Py.IOError(e); } PyCode code; try { code = Py.compile_flags(file, name, CompileMode.exec, cflags); } finally { try { file.close(); } catch (IOException e) { throw Py.IOError(e); } } Py.runCode(code, locals, globals); }
file.close(); Py.runCode(code, locals, locals); } catch (IOException e) { throw Py.IOError(e);
@Override public void transform(StructuredRecord input, final Emitter<StructuredRecord> emitter) { try { Emitter<Map> pythonEmitter = new PythonEmitter(emitter, schema == null ? input.getSchema() : schema); interpreter.set(INPUT_STRUCTURED_RECORD_VARIABLE_NAME, encode(input, input.getSchema())); interpreter.set(EMITTER_VARIABLE_NAME, pythonEmitter); Py.runCode(compiledScript, interpreter.getLocals(), interpreter.getLocals()); } catch (PyException e) { // We put the stack trace as the exception message, because otherwise the information from PyException is lost. // PyException only exposes the actual cause (Python stack trace) if printStackTrace() is called on it. throw new IllegalArgumentException("Could not transform input.\n" + getStackTrace(e)); } }
getCompilerFlags(flags, false)); Py.runCode(code, locals, globals);