当前位置: 首页>>代码示例>>Java>>正文


Java PyException.match方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:RunasSudo,项目名称:PyAndroid,代码行数:19,代码来源:PosixModule.java

示例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;
}
 
开发者ID:RunasSudo,项目名称:PyAndroid,代码行数:29,代码来源:PosixModule.java

示例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;
        }
    }
}
 
开发者ID:RunasSudo,项目名称:PyAndroid,代码行数:12,代码来源:PosixModule.java

示例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");
	}
}
 
开发者ID:araqne,项目名称:jython,代码行数:30,代码来源:JythonScript.java

示例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);
    }
}
 
开发者ID:PonIC,项目名称:PonIC,代码行数:49,代码来源:JythonScriptEngine.java


注:本文中的org.python.core.PyException.match方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。