本文整理汇总了Java中org.python.core.Py.OSError方法的典型用法代码示例。如果您正苦于以下问题:Java Py.OSError方法的具体用法?Java Py.OSError怎么用?Java Py.OSError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.python.core.Py
的用法示例。
在下文中一共展示了Py.OSError方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fdopen
import org.python.core.Py; //导入方法依赖的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: fsync
import org.python.core.Py; //导入方法依赖的package包/类
/**
* Internal fsync implementation.
*/
private static void fsync(PyObject fd, boolean metadata) {
RawIOBase rawIO = FileDescriptors.get(fd);
rawIO.checkClosed();
Channel channel = rawIO.getChannel();
if (!(channel instanceof FileChannel)) {
throw Py.OSError(Errno.EINVAL);
}
try {
((FileChannel)channel).force(metadata);
} catch (ClosedChannelException cce) {
// In the rare case it's closed but the rawIO wasn't
throw Py.ValueError("I/O operation on closed file");
} catch (IOException ioe) {
throw Py.OSError(ioe);
}
}
示例3: unlink
import org.python.core.Py; //导入方法依赖的package包/类
public static void unlink(PyObject path) {
String absolutePath = absolutePath(path);
File file = new File(absolutePath);
if (!file.delete()) {
// Something went wrong, does stat raise an error?
posix.stat(absolutePath);
// It exists, is it a directory, or do we not have permissions?
if (file.isDirectory()) {
throw Py.OSError(Errno.EISDIR, path);
}
if (!file.canWrite()) {
throw Py.OSError(Errno.EPERM, path);
}
throw Py.OSError("unlink(): an unknown error occured" + absolutePath);
}
}
示例4: chdir
import org.python.core.Py; //导入方法依赖的package包/类
public static void chdir(PyObject path) {
// stat raises ENOENT for us if path doesn't exist
if (!posix.stat(absolutePath(path)).isDirectory()) {
throw Py.OSError((Constant)Errno.ENOTDIR, path);
}
if (realpath == null) {
realpath = imp.load("os.path").__getattr__("realpath");
}
Py.getSystemState().setCurrentWorkingDir(realpath.__call__(path).asString());
}
示例5: readlink
import org.python.core.Py; //导入方法依赖的package包/类
@Hide(OS.NT)
public static String readlink(PyObject path) {
try {
return posix.readlink(absolutePath(path));
} catch (IOException ioe) {
throw Py.OSError(ioe);
}
}
示例6: rmdir
import org.python.core.Py; //导入方法依赖的package包/类
public static void rmdir(PyObject path) {
File file = new File(absolutePath(path));
if (!file.exists()) {
throw Py.OSError(Errno.ENOENT, path);
} else if (!file.isDirectory()) {
throw Py.OSError(Errno.ENOTDIR, path);
} else if (!file.delete()) {
PyObject args = new PyTuple(Py.Zero, new PyString("Couldn't delete directory"),
path);
throw new PyException(Py.OSError, args);
}
}
示例7: open
import org.python.core.Py; //导入方法依赖的package包/类
public static FileIO open(PyObject path, int flag, int mode) {
String absolutePath = absolutePath(path);
File file = new File(absolutePath);
boolean reading = (flag & O_RDONLY) != 0;
boolean writing = (flag & O_WRONLY) != 0;
boolean updating = (flag & O_RDWR) != 0;
boolean creating = (flag & O_CREAT) != 0;
boolean appending = (flag & O_APPEND) != 0;
boolean truncating = (flag & O_TRUNC) != 0;
boolean exclusive = (flag & O_EXCL) != 0;
boolean sync = (flag & O_SYNC) != 0;
if (updating && writing) {
throw Py.OSError(Errno.EINVAL, path);
}
if (!creating && !file.exists()) {
throw Py.OSError(Errno.ENOENT, path);
}
if (!writing) {
if (updating) {
writing = true;
} else {
reading = true;
}
}
if (truncating && !writing) {
// Explicitly truncate, writing will truncate anyway
new FileIO((PyString) path, "w").close();
}
if (exclusive && creating) {
try {
if (!file.createNewFile()) {
throw Py.OSError(Errno.EEXIST, path);
}
} catch (IOException ioe) {
throw Py.OSError(ioe);
}
}
String fileIOMode = (reading ? "r" : "") + (!appending && writing ? "w" : "")
+ (appending && (writing || updating) ? "a" : "") + (updating ? "+" : "");
if (sync && (writing || updating)) {
try {
return new FileIO(new RandomAccessFile(file, "rws").getChannel(), fileIOMode);
} catch (FileNotFoundException fnfe) {
throw Py.OSError(file.isDirectory() ? Errno.EISDIR : Errno.ENOENT, path);
}
}
return new FileIO((PyString) path, fileIOMode);
}
示例8: rename
import org.python.core.Py; //导入方法依赖的package包/类
public static void rename(PyObject oldpath, PyObject newpath) {
if (!new File(absolutePath(oldpath)).renameTo(new File(absolutePath(newpath)))) {
PyObject args = new PyTuple(Py.Zero, new PyString("Couldn't rename file"));
throw new PyException(Py.OSError, args);
}
}
示例9: badFD
import org.python.core.Py; //导入方法依赖的package包/类
private static PyException badFD() {
return Py.OSError(Errno.EBADF);
}
示例10: errorFromErrno
import org.python.core.Py; //导入方法依赖的package包/类
private static PyException errorFromErrno() {
return Py.OSError(Errno.valueOf(posix.errno()));
}