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


Python error.wrap_oserror2函数代码示例

本文整理汇总了Python中pypy.interpreter.error.wrap_oserror2函数的典型用法代码示例。如果您正苦于以下问题:Python wrap_oserror2函数的具体用法?Python wrap_oserror2怎么用?Python wrap_oserror2使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了wrap_oserror2函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: utime

def utime(space, w_path, w_tuple):
    """ utime(path, (atime, mtime))
utime(path, None)

Set the access and modified time of the file to the given values.  If the
second form is used, set the access and modified times to the current time.
    """
    if space.is_w(w_tuple, space.w_None):
        try:
            dispatch_filename(rposix.utime, 1)(space, w_path, None)
            return
        except OSError as e:
            raise wrap_oserror2(space, e, w_path)
    try:
        msg = "utime() arg 2 must be a tuple (atime, mtime) or None"
        args_w = space.fixedview(w_tuple)
        if len(args_w) != 2:
            raise oefmt(space.w_TypeError, msg)
        actime = space.float_w(args_w[0], allow_conversion=False)
        modtime = space.float_w(args_w[1], allow_conversion=False)
        dispatch_filename(rposix.utime, 2)(space, w_path, (actime, modtime))
    except OSError as e:
        raise wrap_oserror2(space, e, w_path)
    except OperationError as e:
        if not e.match(space, space.w_TypeError):
            raise
        raise oefmt(space.w_TypeError, msg)
开发者ID:mozillazg,项目名称:pypy,代码行数:27,代码来源:interp_posix.py

示例2: statvfs

def statvfs(space, w_path):
    try:
        st = dispatch_filename(rposix_stat.statvfs)(space, w_path)
    except OSError as e:
        raise wrap_oserror2(space, e, w_path)
    else:
        return build_statvfs_result(space, st)
开发者ID:mozillazg,项目名称:pypy,代码行数:7,代码来源:interp_posix.py

示例3: open

def open(space, w_fname, flag, mode=0777):
    """Open a file (for low level IO).
Return a file descriptor (a small integer)."""
    try:
        fd = dispatch_filename(rposix.open)(space, w_fname, flag, mode)
    except OSError, e:
        raise wrap_oserror2(space, e, w_fname)
开发者ID:are-prabhu,项目名称:pypy,代码行数:7,代码来源:interp_posix.py

示例4: listdir

def listdir(space, w_dirname):
    """Return a list containing the names of the entries in the directory.

\tpath: path of directory to list

The list is in arbitrary order.  It does not include the special
entries '.' and '..' even if they are present in the directory."""
    try:
        if space.isinstance_w(w_dirname, space.w_unicode):
            dirname = FileEncoder(space, w_dirname)
            result = rposix.listdir(dirname)
            len_result = len(result)
            result_w = [None] * len_result
            for i in range(len_result):
                if _WIN32:
                    result_w[i] = space.wrap(result[i])
                else:
                    w_bytes = space.wrapbytes(result[i])
                    result_w[i] = space.fsdecode(w_bytes)
            return space.newlist(result_w)
        else:
            dirname = space.str0_w(w_dirname)
            result = rposix.listdir(dirname)
            # The list comprehension is a workaround for an obscure translation
            # bug.
            return space.newlist_bytes([x for x in result])
    except OSError, e:
        raise wrap_oserror2(space, e, w_dirname)
开发者ID:Qointum,项目名称:pypy,代码行数:28,代码来源:interp_posix.py

示例5: lstat

def lstat(space, w_path):
    "Like stat(path), but do not follow symbolic links."
    try:
        st = dispatch_filename(rposix_stat.lstat)(space, w_path)
    except OSError as e:
        raise wrap_oserror2(space, e, w_path)
    else:
        return build_stat_result(space, st)
开发者ID:mozillazg,项目名称:pypy,代码行数:8,代码来源:interp_posix.py

示例6: descr_init

    def descr_init(self, space, w_name, mode='r', closefd=True):
        if space.isinstance_w(w_name, space.w_float):
            raise oefmt(space.w_TypeError,
                        "integer argument expected, got float")

        fd = -1
        try:
            fd = space.c_int_w(w_name)
        except OperationError as e:
            pass
        else:
            if fd < 0:
                raise oefmt(space.w_ValueError, "negative file descriptor")

        self.readable, self.writable, self.appending, flags = decode_mode(space, mode)

        fd_is_own = False
        try:
            if fd >= 0:
                try:
                    os.fstat(fd)
                except OSError as e:
                    if e.errno == errno.EBADF:
                        raise wrap_oserror(space, e)
                    # else: pass
                self.fd = fd
                self.closefd = bool(closefd)
            else:
                self.closefd = True
                if not closefd:
                    raise oefmt(space.w_ValueError,
                                "Cannot use closefd=False with file name")

                from pypy.module.posix.interp_posix import (
                    dispatch_filename, rposix)
                try:
                    self.fd = dispatch_filename(rposix.open)(
                        space, w_name, flags, 0666)
                except OSError as e:
                    raise wrap_oserror2(space, e, w_name,
                                        exception_name='w_IOError')
                finally:
                    fd_is_own = True

            self._dircheck(space, w_name)
            space.setattr(self, space.wrap("name"), w_name)

            if self.appending:
                # For consistent behaviour, we explicitly seek to the end of file
                # (otherwise, it might be done only on the first write()).
                try:
                    os.lseek(self.fd, 0, os.SEEK_END)
                except OSError as e:
                    raise wrap_oserror(space, e, exception_name='w_IOError')
        except:
            if not fd_is_own:
                self.fd = -1
            raise
开发者ID:mozillazg,项目名称:pypy,代码行数:58,代码来源:interp_fileio.py

示例7: _getfinalpathname

 def _getfinalpathname(space, w_path):
     path = space.unicode_w(w_path)
     try:
         result = nt._getfinalpathname(path)
     except nt.LLNotImplemented as e:
         raise OperationError(space.w_NotImplementedError,
                              space.wrap(e.msg))
     except OSError as e:
         raise wrap_oserror2(space, e, w_path)
     return space.wrap(result)
开发者ID:Qointum,项目名称:pypy,代码行数:10,代码来源:interp_posix.py

示例8: readlink

def readlink(space, w_path):
    "Return a string representing the path to which the symbolic link points."
    is_unicode = space.isinstance_w(w_path, space.w_unicode)
    if is_unicode:
        path = space.fsencode_w(w_path)
    else:
        path = space.bytes0_w(w_path)
    try:
        result = os.readlink(path)
    except OSError, e:
        raise wrap_oserror2(space, e, w_path)
开发者ID:Qointum,项目名称:pypy,代码行数:11,代码来源:interp_posix.py

示例9: _dircheck

 def _dircheck(self, space, w_filename):
     # On Unix, fopen will succeed for directories.
     # In Python, there should be no file objects referring to
     # directories, so we need a check.
     if self.fd < 0:
         return
     try:
         st = os.fstat(self.fd)
     except OSError:
         return
     if stat.S_ISDIR(st.st_mode):
         raise wrap_oserror2(space, OSError(errno.EISDIR, "fstat"),
                             w_filename, exception_name='w_IOError')
开发者ID:Qointum,项目名称:pypy,代码行数:13,代码来源:interp_fileio.py

示例10: bool

                    # else: pass
                self.fd = fd
                self.closefd = bool(closefd)
            else:
                self.closefd = True
                if not closefd:
                    raise OperationError(space.w_ValueError, space.wrap(
                        "Cannot use closefd=False with file name"))

                from pypy.module.posix.interp_posix import (
                    dispatch_filename, rposix)
                try:
                    self.fd = dispatch_filename(rposix.open)(
                        space, w_name, flags, 0666)
                except OSError, e:
                    raise wrap_oserror2(space, e, w_name,
                                        exception_name='w_IOError')
                finally:
                    fd_is_own = True

            self._dircheck(space, w_name)
            space.setattr(self, space.wrap("name"), w_name)

            if self.appending:
                # For consistent behaviour, we explicitly seek to the end of file
                # (otherwise, it might be done only on the first write()).
                try:
                    os.lseek(self.fd, 0, os.SEEK_END)
                except OSError, e:
                    raise wrap_oserror(space, e, exception_name='w_IOError')
        except:
            if not fd_is_own:
开发者ID:Qointum,项目名称:pypy,代码行数:32,代码来源:interp_fileio.py

示例11: wrap_oserror2

                    result_w[i] = space.call_method(w_bytes,
                                                    "decode", w_fs_encoding)
                except OperationError as e:
                    # fall back to the original byte string
                    if e.async(space):
                        raise
                    result_w[i] = w_bytes
            return space.newlist(result_w)
        else:
            dirname = space.str0_w(w_dirname)
            result = rposix.listdir(dirname)
            # The list comprehension is a workaround for an obscure translation
            # bug.
            return space.newlist_bytes([x for x in result])
    except OSError as e:
        raise wrap_oserror2(space, e, w_dirname)

def pipe(space):
    "Create a pipe.  Returns (read_end, write_end)."
    try:
        fd1, fd2 = os.pipe()
    except OSError as e:
        raise wrap_oserror(space, e)
    return space.newtuple([space.wrap(fd1), space.wrap(fd2)])

@unwrap_spec(mode=c_int)
def chmod(space, w_path, mode):
    "Change the access permissions of a file."
    try:
        dispatch_filename(rposix.chmod)(space, w_path, mode)
    except OSError as e:
开发者ID:mozillazg,项目名称:pypy,代码行数:31,代码来源:interp_posix.py

示例12: wrap_oserror_as_ioerror

def wrap_oserror_as_ioerror(space, e, w_filename=None):
    return wrap_oserror2(space, e, w_filename,
                         w_exception_class=space.w_IOError)
开发者ID:gorakhargosh,项目名称:pypy,代码行数:3,代码来源:interp_stream.py


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