本文整理汇总了Java中org.python.core.PyException.match方法的典型用法代码示例。如果您正苦于以下问题:Java PyException.match方法的具体用法?Java PyException.match怎么用?Java PyException.match使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.python.core.PyException
的用法示例。
在下文中一共展示了PyException.match方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
}
示例3: unsetenv
import org.python.core.PyException; //导入方法依赖的package包/类
public static void unsetenv(String key) {
// import os; try: del os.environ[key]; except KeyError: pass
PyObject environ = imp.load("os").__getattr__("environ");
try {
environ.__delitem__(key);
} catch (PyException pye) {
if (!pye.match(Py.KeyError)) {
throw pye;
}
}
}
示例4: run
import org.python.core.PyException; //导入方法依赖的package包/类
public void run(String[] args) {
String name = null;
if (args.length > 0)
name = args[0];
InteractiveConsole interpreter = getInterpreter(name);
JythonOutputStream os = new JythonOutputStream(context);
interpreter.setOut(os);
interpreter.setErr(os);
try {
boolean more = false;
while (true) {
String line;
try {
context.print(more ? "... " : ">>> ");
line = context.readLine();
} catch (PyException exc) {
if (!exc.match(Py.EOFError))
throw exc;
break;
}
more = interpreter.push(line);
}
} catch (InterruptedException e) {
context.println("interrupted");
}
}
示例5: execfile
import org.python.core.PyException; //导入方法依赖的package包/类
/**
* does not call script.close()
* @param script
* @param path
* @param pigContext
* @throws ExecException
*/
static void execfile(InputStream script, String path, PigContext pigContext) throws ExecException {
try {
// determine the current module state
Map<String, String> before = pigContext != null ? getModuleState() : null;
// exec the code, arbitrary imports are processed
interpreter.execfile(script, path);
// determine the 'post import' module state
Map<String, String> after = pigContext != null ? getModuleState() : null;
// add the module files to the context
if (after != null && pigContext != null) {
after.keySet().removeAll(before.keySet());
for (Map.Entry<String, String> entry : after.entrySet()) {
String modulename = entry.getKey();
String modulepath = entry.getValue();
if (modulepath.equals(JVM_JAR)) {
continue;
} else if (modulepath.endsWith(".jar") || modulepath.endsWith(".zip")) {
pigContext.scriptJars.add(modulepath);
} else {
pigContext.addScriptFile(modulename, modulepath);
}
}
}
} catch (PyException e) {
if (e.match(Py.SystemExit)) {
PyObject value = e.value;
if (PyException.isExceptionInstance(e.value)) {
value = value.__findattr__("code");
}
if (new PyInteger(0).equals(value)) {
LOG.info("Script invoked sys.exit(0)");
return;
}
}
String message = "Python Error. " + e;
throw new ExecException(message, 1121, e);
}
}