public Object evaluate(String script) { try { interpreter.exec(script); } catch (org.python.core.PyException e) { throw new InterpreterException(e, e.getMessage(), -1, -1); } catch (RuntimeException re) { throw new InterpreterException(re, re.getMessage(), -1, -1); } return null; }
/** * Construct a PyBuffer on a given object suitable for reading into from the underlying stream. * The buffer returned will be navigable as a 1D contiguous writable sequence of bytes. * * @param obj to be wrapped and presented as a buffer * @return a 1D contiguous PyBuffer of bytes * @throws PyException (BufferError) if object has buffer API, but is not 1D contiguous bytes * @throws PyException (TypeError) if object not convertible to a byte array */ protected static PyBuffer writablePyBuffer(PyObject obj) throws PyException { if (obj instanceof BufferProtocol) { try { return ((BufferProtocol)obj).getBuffer(PyBUF.WRITABLE); } catch (PyException pye) { if (pye.match(Py.BufferError)) { // If we can't get a buffer on the object, say it's the wrong type throw Py.TypeError(String.format("(BufferError) %s", pye.getMessage())); } else { throw pye; } } } else { // Can't be a buffer: complain throw tailoredTypeError("read-write buffer", obj); } }
if (pye.match(Py.BufferError)) { throw Py.TypeError(String.format("(BufferError) %s", pye.getMessage())); } else { throw pye;