本文整理汇总了Java中org.python.core.PyException类的典型用法代码示例。如果您正苦于以下问题:Java PyException类的具体用法?Java PyException怎么用?Java PyException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PyException类属于org.python.core包,在下文中一共展示了PyException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fdopen
import org.python.core.PyException; //导入依赖的package包/类
public static PyObject fdopen(PyObject fd, String mode, int bufsize) {
if (mode.length() == 0 || !"rwa".contains("" + mode.charAt(0))) {
throw Py.ValueError(String.format("invalid file mode '%s'", mode));
}
RawIOBase rawIO = FileDescriptors.get(fd);
if (rawIO.closed()) {
throw badFD();
}
try {
return new PyFile(rawIO, "<fdopen>", mode, bufsize);
} catch (PyException pye) {
if (!pye.match(Py.IOError)) {
throw pye;
}
throw Py.OSError((Constant)Errno.EINVAL);
}
}
示例2: callFunc
import org.python.core.PyException; //导入依赖的package包/类
public static Object callFunc(Class<?> c, String funcName, Object... binds) {
try {
PyObject obj = ScriptManager.python.get(funcName);
if (obj != null && obj instanceof PyFunction) {
PyFunction func = (PyFunction) obj;
PyObject[] objects = new PyObject[binds.length];
for (int i = 0; i < binds.length; i++) {
Object bind = binds[i];
objects[i] = Py.java2py(bind);
}
return func.__call__(objects).__tojava__(c);
} else
return null;
} catch (PyException ex) {
ex.printStackTrace();
return null;
}
}
示例3: runTestOnce
import org.python.core.PyException; //导入依赖的package包/类
private void runTestOnce(String testScript, PythonInterpreter interp, int invocationsSoFar)
{
try
{
interp.execfile(testScript);
}
catch (PyException e)
{
if( e.type.toString().equals("<type 'exceptions.SystemExit'>") && e.value.toString().equals("0") )
{
// Build succeeded.
}
else
{
if (LOGGER.isLoggable(Level.FINE))
{
LOGGER.log(Level.FINE, "Jython interpreter failed. Test failures?", e);
}
// This unusual code is necessary because PyException toString() contains the useful Python traceback
// and getMessage() is usually null
fail("Caught PyException on invocation number " + invocationsSoFar + ": " + e.toString() + " with message: " + e.getMessage());
}
}
}
示例4: run
import org.python.core.PyException; //导入依赖的package包/类
/**
* Runs the task
*/
public void run() {
try {
PyContext.setPlugin(this.plugin);
if (exec) {
interpreter.exec(code);
} else {
result.more = interpreter.runsource(code);
}
} catch (PyException e) {
result.exception = e;
} finally {
PyContext.setPlugin(null);
// notify other call
synchronized (result) {
result.done = true;
result.notifyAll();
}
}
}
示例5: run
import org.python.core.PyException; //导入依赖的package包/类
@Override
public void run() {
try {
PyContext.setPlugin(this.plugin);
if (exec) {
interpreter.execfile(this.script.getAbsolutePath());
}
} catch (PyException e){
result.exception = e;
} finally {
PyContext.setPlugin(null);
synchronized (result){
result.done = true;
result.notifyAll();
}
}
}
示例6: executeCommand
import org.python.core.PyException; //导入依赖的package包/类
public void executeCommand(String commands) {
StringBuilder text;
moreCommand += commands;
try {
// If command is not finished (i.e. loop)
if(interp.runsource(moreCommand)) {
text = new StringBuilder(getText());
text.append(ps2);
moreCommand += "\n";
} else {
text = new StringBuilder(getText());
text.append(ps1);
moreCommand = "";
}
setText(text.toString());
} catch (PyException e) {
e.printStackTrace();
}
fireCommandExecuted(commands);
}
示例7: evalLookupLexer
import org.python.core.PyException; //导入依赖的package包/类
private Object evalLookupLexer(PyGateway gateway, String alias, Object notFoundFallback) {
Object result;
try {
PythonInterpreter interpreter = gateway.getInterpreter();
interpreter.set("alias", alias);
interpreter.exec(""
+ "from pygments.lexers import get_lexer_by_name\n"
+ "result = get_lexer_by_name(alias)");
result = interpreter.get("result");
} catch (PyException e) {
log.warn("Unable to find Pygments lexer for alias '{}'", alias);
result = notFoundFallback;
}
return result;
}
示例8: getElementCenter
import org.python.core.PyException; //导入依赖的package包/类
/**
* Get the coordinates of the element's center.
*
* @param selector
* the element selector
* @return the (x,y) coordinates of the center
* @throws IOException
* @throws UnsupportedEncodingException
* @throws RecognitionException
*/
private Point getElementCenter(By selector, ControlHierarchy ch)
throws UnsupportedEncodingException, IOException,
RecognitionException {
List<ITreeNode> result = selector.query(ch.getAllNodes());
if (result == null) {
throw new PyException(Py.ValueError, String.format(
"找不到iQuery语句指定的控件: %s", selector.getSelector()));
}
if (result.size() != 1) {
throw new PyException(Py.ValueError, String.format(
"iQuery查询语句找到多于一个控件: %s", selector.getSelector()));
}
ITreeNode node = result.get(0);
Point p = getAbsoluteCenterOfView(node);
return p;
}
示例9: execute
import org.python.core.PyException; //导入依赖的package包/类
/**
* Executes a python script, returning its output or not.
*
* @param fileName the filename of the python script to execute
* @param redirectOutput true to redirect outputs and return them, false otherwise
* @param arguments the arguments to pass to the python script
* @return the output of the python script execution (combined standard and error outputs) or null if outputs were not
* redirected
* @throws PyException in case of exception during Python script execution
*/
public static String execute(String fileName, boolean redirectOutput, String... arguments) throws PyException {
Properties properties = new Properties();
properties.setProperty("python.home", StaticConfiguration.JYTHON_HOME);
properties.setProperty("python.path", StaticConfiguration.FORMATTER_DIR);
PythonInterpreter.initialize(System.getProperties(), properties, new String[] {""});
try (PythonInterpreter interp = new PythonInterpreter(new org.python.core.PyStringMap(),
new org.python.core.PySystemState())) {
StringWriter output = null;
if (redirectOutput) {
output = new StringWriter();
interp.setOut(output);
interp.setErr(output);
}
interp.cleanup();
interp.exec("import sys;sys.argv[1:]= [r'" + StringUtils.join(arguments, "','") + "']");
interp.exec("__name__ = '__main__'");
interp.exec("execfile(r'" + fileName + "')");
return redirectOutput ? output.toString() : null;
}
}
示例10: badModule
import org.python.core.PyException; //导入依赖的package包/类
@Test(expected=PyException.class)
public void badModule() throws Exception {
JythonGeneratorModel model = new JythonGeneratorModel();
model.setPath("src/org/eclipse/scanning/test/points");
model.setModuleName("fred");
model.setClassName("FixedValueGenerator");
IPointGenerator<JythonGeneratorModel> gen = service.createGenerator(model);
gen.size();
}
示例11: badClass
import org.python.core.PyException; //导入依赖的package包/类
@Test(expected=PyException.class)
public void badClass() throws Exception {
JythonGeneratorModel model = new JythonGeneratorModel();
model.setPath("src/org/eclipse/scanning/test/points");
model.setModuleName("JythonGeneratorTest");
model.setClassName("fred");
IPointGenerator<JythonGeneratorModel> gen = service.createGenerator(model);
gen.size();
}
示例12: exceptionInGenerator
import org.python.core.PyException; //导入依赖的package包/类
@Test(expected=PyException.class)
public void exceptionInGenerator() throws Exception {
JythonGeneratorModel model = new JythonGeneratorModel();
model.setPath("src/org/eclipse/scanning/test/points");
model.setModuleName("JythonGeneratorTest");
model.setClassName("ExceptionGenerator");
IPointGenerator<JythonGeneratorModel> gen = service.createGenerator(model);
gen.size();
}
示例13: adjustException
import org.python.core.PyException; //导入依赖的package包/类
private static RuntimeException adjustException(ScriptException scriptException, String... scripts) {
Throwable cause = scriptException.getCause();
if (!(cause instanceof PyException)) {
if (scripts.length == 0) {
return new IllegalStateException(scriptException);
} else {
return new IllegalStateException(
scriptException.getMessage() + "\nscript:" + joinStrings("\n", scripts), scriptException);
}
}
PyException e = (PyException) cause;
PyObject o = e.value.getDict();
if (!(o instanceof PyStringMap)) {
return e;
}
PyStringMap m = (PyStringMap) o;
String message;
if (e.value instanceof PyBaseException) {
message = String.valueOf(((PyBaseException) e.value).getMessage());
} else {
message = scriptException.getMessage();
}
PyObject tlist = m.getMap().get("tlist");
PyObject trace = m.getMap().get("trace");
return new UroborosqlFormatterException(message, String.valueOf(tlist), String.valueOf(trace), e);
}
示例14: access
import org.python.core.PyException; //导入依赖的package包/类
public static boolean access(PyObject path, int mode) {
String absolutePath = absolutePath(path);
File file = new File(absolutePath);
boolean result = true;
if (!file.exists()) {
result = false;
}
if ((mode & R_OK) != 0 && !file.canRead()) {
result = false;
}
if ((mode & W_OK) != 0 && !file.canWrite()) {
result = false;
}
if ((mode & X_OK) != 0) {
// NOTE: always true without native jna-posix stat
try {
result = posix.stat(absolutePath).isExecutable();
} catch (PyException pye) {
if (!pye.match(Py.OSError)) {
throw pye;
}
// ENOENT
result = false;
}
}
return result;
}
示例15: close
import org.python.core.PyException; //导入依赖的package包/类
public static void close(PyObject fd) {
try {
FileDescriptors.get(fd).close();
} catch (PyException pye) {
throw badFD();
}
}