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


Python error.wrap_oserror函数代码示例

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


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

示例1: test_wrap_oserror

def test_wrap_oserror():
    class FakeSpace:
        w_OSError = [OSError]
        w_EnvironmentError = [EnvironmentError]
        def wrap(self, obj):
            return [obj]
        def call_function(self, exc, w_errno, w_msg, w_filename=None):
            return (exc, w_errno, w_msg, w_filename)
    space = FakeSpace()
    #
    e = wrap_oserror(space, OSError(errno.EBADF, "foobar"))
    assert isinstance(e, OperationError)
    assert e.w_type == [OSError]
    assert e.get_w_value(space) == ([OSError], [errno.EBADF],
                                    [os.strerror(errno.EBADF)], None)
    #
    e = wrap_oserror(space, OSError(errno.EBADF, "foobar"),
                     filename = "test.py",
                     exception_name = "w_EnvironmentError")
    assert isinstance(e, OperationError)
    assert e.w_type == [EnvironmentError]
    assert e.get_w_value(space) == ([EnvironmentError], [errno.EBADF],
                                    [os.strerror(errno.EBADF)],
                                    ["test.py"])
    #
    e = wrap_oserror(space, OSError(errno.EBADF, "foobar"),
                     filename = "test.py",
                     w_exception_class = [SystemError])
    assert isinstance(e, OperationError)
    assert e.w_type == [SystemError]
    assert e.get_w_value(space) == ([SystemError], [errno.EBADF],
                                    [os.strerror(errno.EBADF)],
                                    ["test.py"])
开发者ID:charred,项目名称:pypy,代码行数:33,代码来源:test_error.py

示例2: execve

def execve(space, w_command, w_args, w_env):
    """ execve(path, args, env)

Execute a path with arguments and environment, replacing current process.

        path: path of executable file
        args: iterable of arguments
        env: dictionary of strings mapping to strings
    """
    command = fsencode_w(space, w_command)
    try:
        args_w = space.unpackiterable(w_args)
        if len(args_w) < 1:
            raise oefmt(space.w_ValueError,
                        "execv() must have at least one argument")
        args = [fsencode_w(space, w_arg) for w_arg in args_w]
    except OperationError as e:
        if not e.match(space, space.w_TypeError):
            raise
        raise oefmt(space.w_TypeError,
                    "execv() arg 2 must be an iterable of strings")
    #
    if w_env is None:    # when called via execv() above
        try:
            os.execv(command, args)
        except OSError as e:
            raise wrap_oserror(space, e)
    else:
        env = _env2interp(space, w_env)
        try:
            os.execve(command, args, env)
        except OSError as e:
            raise wrap_oserror(space, e)
开发者ID:mozillazg,项目名称:pypy,代码行数:33,代码来源:interp_posix.py

示例3: 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

示例4: openpty

def openpty(space):
    "Open a pseudo-terminal, returning open fd's for both master and slave end."
    try:
        master_fd, slave_fd = os.openpty()
    except OSError as e:
        raise wrap_oserror(space, e)
    return space.newtuple([space.wrap(master_fd), space.wrap(slave_fd)])
开发者ID:mozillazg,项目名称:pypy,代码行数:7,代码来源:interp_posix.py

示例5: _getfullpathname

def _getfullpathname(space, path):
    """helper for ntpath.abspath """
    posix = __import__(os.name) # nt specific
    try:
        fullpath = posix._getfullpathname(path)
    except OSError, e:
        raise wrap_oserror(space, e) 
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:7,代码来源:interp_posix.py

示例6: spawnve

def spawnve(space, mode, path, w_args, w_env):
    args = [space.str0_w(w_arg) for w_arg in space.unpackiterable(w_args)]
    env = _env2interp(space, w_env)
    try:
        ret = os.spawnve(mode, path, args, env)
    except OSError, e:
        raise wrap_oserror(space, e)
开发者ID:ParitoshThapliyal59,项目名称:pypy,代码行数:7,代码来源:interp_posix.py

示例7: lchown

def lchown(space, path, uid, gid):
    """Change the owner and group id of path to the numeric uid and gid.
This function will not follow symbolic links."""
    try:
        os.lchown(path, uid, gid)
    except OSError as e:
        raise wrap_oserror(space, e, path)
开发者ID:mozillazg,项目名称:pypy,代码行数:7,代码来源:interp_posix.py

示例8: confstr

def confstr(space, w_name):
    num = confname_w(space, w_name, os.confstr_names)
    try:
        res = os.confstr(num)
    except OSError as e:
        raise wrap_oserror(space, e)
    return space.wrap(res)
开发者ID:mozillazg,项目名称:pypy,代码行数:7,代码来源:interp_posix.py

示例9: pathconf

def pathconf(space, path, w_name):
    num = confname_w(space, w_name, os.pathconf_names)
    try:
        res = os.pathconf(path, num)
    except OSError as e:
        raise wrap_oserror(space, e)
    return space.wrap(res)
开发者ID:mozillazg,项目名称:pypy,代码行数:7,代码来源:interp_posix.py

示例10: open_cdll

def open_cdll(space, name):
    try:
        return CDLL(name)
    except DLOpenError as e:
        raise wrap_dlopenerror(space, e, name or "<None>")
    except OSError as e:
        raise wrap_oserror(space, e)
开发者ID:mozillazg,项目名称:pypy,代码行数:7,代码来源:interp_rawffi.py

示例11: _dump_rpy_heap

def _dump_rpy_heap(space, fd):
    try:
        ok = rgc.dump_rpy_heap(fd)
    except OSError as e:
        raise wrap_oserror(space, e)
    if not ok:
        raise missing_operation(space)
开发者ID:mozillazg,项目名称:pypy,代码行数:7,代码来源:referents.py

示例12: isatty_w

 def isatty_w(self, space):
     self._check_closed(space)
     try:
         res = os.isatty(self.fd)
     except OSError as e:
         raise wrap_oserror(space, e, exception_name='w_IOError')
     return space.wrap(res)
开发者ID:mozillazg,项目名称:pypy,代码行数:7,代码来源:interp_fileio.py

示例13: enable

 def enable(self, space, fileno, period_usec):
     if self.is_enabled:
         raise oefmt(space.w_ValueError, "_vmprof already enabled")
     self.fileno = fileno
     self.is_enabled = True
     self.write_header(fileno, period_usec)
     if not self.ever_enabled:
         if we_are_translated():
             res = pypy_vmprof_init()
             if res:
                 raise OperationError(
                     space.w_IOError,
                     space.wrap(rffi.charp2str(vmprof_get_error())))
         self.ever_enabled = True
     self.gather_all_code_objs(space)
     space.register_code_callback(vmprof_register_code)
     if we_are_translated():
         # does not work untranslated
         res = vmprof_enable(fileno, period_usec, 0,
                             lltype.nullptr(rffi.CCHARP.TO), 0)
     else:
         res = 0
     if res == -1:
         raise wrap_oserror(space, OSError(rposix.get_saved_errno(),
                                           "_vmprof.enable"))
开发者ID:pypyjs,项目名称:pypy,代码行数:25,代码来源:interp_vmprof.py

示例14: nice

def nice(space, inc):
    "Decrease the priority of process by inc and return the new priority."
    try:
        res = os.nice(inc)
    except OSError as e:
        raise wrap_oserror(space, e)
    return space.wrap(res)
开发者ID:mozillazg,项目名称:pypy,代码行数:7,代码来源:interp_posix.py

示例15: open

def open(space, fname, flag, mode=0777):
    """Open a file (for low level IO).
Return a file descriptor (a small integer)."""
    try: 
        fd = os.open(fname, flag, mode)
    except OSError, e: 
        raise wrap_oserror(space, e) 
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:7,代码来源:interp_posix.py


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