示例#1
0
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"])
示例#2
0
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)
示例#3
0
    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
示例#4
0
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)])
示例#5
0
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)
示例#6
0
def isatty(space, fd):
    """Return True if 'fd' is an open file descriptor connected to the
slave end of a terminal."""
    try:
        res = os.isatty(fd)
    except OSError, e:
        raise wrap_oserror(space, e)
示例#7
0
    def readall_w(self, space):
        self._check_closed(space)
        self._check_readable(space)
        total = 0

        builder = StringBuilder()
        while True:
            newsize = int(new_buffersize(self.fd, total))

            try:
                chunk = os.read(self.fd, newsize - total)
            except OSError, e:
                if e.errno == errno.EINTR:
                    space.getexecutioncontext().checksignals()
                    continue
                if total > 0:
                    # return what we've got so far
                    break
                if e.errno == errno.EAGAIN:
                    return space.w_None
                raise wrap_oserror(space, e,
                                   exception_name='w_IOError')

            if not chunk:
                break
            builder.append(chunk)
            total += len(chunk)
示例#8
0
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)
示例#9
0
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)
示例#10
0
def readlink(space, path):
    "Return a string representing the path to which the symbolic link points."
    try:
        result = os.readlink(path)
    except OSError as e:
        raise wrap_oserror(space, e, path)
    return space.wrap(result)
示例#11
0
def lchown(space, path, uid, gid):
    check_uid_range(space, uid)
    check_uid_range(space, gid)
    try:
        os.lchown(path, uid, gid)
    except OSError, e:
        raise wrap_oserror(space, e, path)
示例#12
0
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)
示例#13
0
 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"))
示例#14
0
def write(space, fd, data):
    """Write a string to a file descriptor.  Return the number of bytes
actually written, which may be smaller than len(data)."""
    try:
        res = os.write(fd, data)
    except OSError, e:
        raise wrap_oserror(space, e)
示例#15
0
def fstatvfs(space, fd):
    try:
        st = rposix_stat.fstatvfs(fd)
    except OSError as e:
        raise wrap_oserror(space, e)
    else:
        return build_statvfs_result(space, st)
示例#16
0
def fsync(space, w_fd):
    """Force write of file with filedescriptor to disk."""
    fd = space.c_filedescriptor_w(w_fd)
    try:
        os.fsync(fd)
    except OSError, e:
        raise wrap_oserror(space, e)
示例#17
0
def spawnv(space, mode, path, w_args):
    args = [space.str0_w(w_arg) for w_arg in space.unpackiterable(w_args)]
    try:
        ret = os.spawnv(mode, path, args)
    except OSError as e:
        raise wrap_oserror(space, e)
    return space.wrap(ret)
示例#18
0
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)
示例#19
0
def fstat(space, fd):
    """Perform a stat system call on the file referenced to by an open
file descriptor."""
    try:
        st = os.fstat(fd)
    except OSError, e:
        raise wrap_oserror(space, e)
示例#20
0
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) 
示例#21
0
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)])
示例#22
0
 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)
示例#23
0
def getpid(space):
    "Return the current process id."
    try:
        pid = os.getpid()
    except OSError as e:
        raise wrap_oserror(space, e)
    return space.wrap(pid)
示例#24
0
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)
示例#25
0
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) 
示例#26
0
def dup(space, fd):
    """Create a copy of the file descriptor.  Return the new file
descriptor."""
    try:
        newfd = os.dup(fd)
    except OSError, e:
        raise wrap_oserror(space, e)
示例#27
0
 def seek_w(self, space, pos, whence=0):
     self._check_closed(space)
     try:
         pos = os.lseek(self.fd, pos, whence)
     except OSError, e:
         raise wrap_oserror(space, e,
                            exception_name='w_IOError')
示例#28
0
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)
示例#29
0
 def tell_w(self, space):
     self._check_closed(space)
     try:
         pos = os.lseek(self.fd, 0, 1)
     except OSError, e:
         raise wrap_oserror(space, e,
                            exception_name='w_IOError')
示例#30
0
def unsetenv(space, name):
    """Delete an environment variable."""
    try:
        del os.environ[name]
    except KeyError:
        pass
    except OSError, e:
        raise wrap_oserror(space, e)
示例#31
0
def putenv(space, name, value):
    """Change or add an environment variable."""
    if _WIN32 and len(name) > _MAX_ENV:
        raise OperationError(
            space.w_ValueError,
            space.wrap("the environment variable is longer than %d bytes" %
                       _MAX_ENV))
    try:
        os.environ[name] = value
    except OSError, e:
        raise wrap_oserror(space, e)
示例#32
0
def listdir(space, 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:
        result = os.listdir(dirname)
    except OSError, e:
        raise wrap_oserror(space, e)
示例#33
0
def prepare_file_argument(space, fileobj):
    fileobj.direct_flush()
    if fileobj.cffi_fileobj is None:
        fd = fileobj.direct_fileno()
        if fd < 0:
            raise OperationError(space.w_ValueError,
                                 space.wrap("file has no OS file descriptor"))
        try:
            fileobj.cffi_fileobj = CffiFileObj(fd, fileobj.mode)
        except OSError, e:
            raise wrap_oserror(space, e)
示例#34
0
 def readinto_w(self, space, w_buffer):
     self._check_closed(space)
     self._check_readable(space)
     rwbuffer = space.rwbuffer_w(w_buffer)
     length = rwbuffer.getlength()
     try:
         buf = os.read(self.fd, length)
     except OSError, e:
         if e.errno == errno.EAGAIN:
             return space.w_None
         raise wrap_oserror(space, e, exception_name='w_IOError')
示例#35
0
    def write_w(self, space, w_data):
        self._check_closed(space)
        self._check_writable(space)
        data = space.getarg_w('y*', w_data).as_str()

        try:
            n = os.write(self.fd, data)
        except OSError, e:
            if e.errno == errno.EAGAIN:
                return space.w_None
            raise wrap_oserror(space, e, exception_name='w_IOError')
示例#36
0
def setregid(space, rgid, egid):
    """ setregid(rgid, egid)

    Set the current process's real and effective group ids.
    """
    check_uid_range(space, rgid)
    check_uid_range(space, egid)
    try:
        os.setregid(rgid, egid)
    except OSError, e:
        raise wrap_oserror(space, e)
示例#37
0
def uname(space):
    """ uname() -> (sysname, nodename, release, version, machine)

    Return a tuple identifying the current operating system.
    """
    try:
        r = os.uname()
    except OSError as e:
        raise wrap_oserror(space, e)
    l_w = [space.newfilename(i) for i in [r[0], r[1], r[2], r[3], r[4]]]
    return space.newtuple(l_w)
示例#38
0
def mmap_error(space, e):
    if isinstance(e, RValueError):
        return OperationError(space.w_ValueError, space.wrap(e.message))
    elif isinstance(e, RTypeError):
        return OperationError(space.w_TypeError, space.wrap(e.message))
    elif isinstance(e, OSError):
        w_error = space.fromcache(Cache).w_error
        return wrap_oserror(space, e, w_exception_class=w_error)
    else:
        # bogus 'e'?
        return OperationError(space.w_SystemError, space.wrap('%s' % e))
示例#39
0
def initgroups(space, username, gid):
    """ initgroups(username, gid) -> None
    
    Call the system initgroups() to initialize the group access list with all of
    the groups of which the specified username is a member, plus the specified
    group id.
    """
    try:
        os.initgroups(username, gid)
    except OSError as e:
        raise wrap_oserror(space, e)
示例#40
0
    def _close(self, space):
        if self.fd < 0:
            return
        fd = self.fd
        self.fd = -1

        try:
            verify_fd(fd)
            os.close(fd)
        except OSError, e:
            raise wrap_oserror(space, e, exception_name='w_IOError')
示例#41
0
def prepare_file_argument(space, w_fileobj):
    w_fileobj.direct_flush()
    if w_fileobj.cffi_fileobj is None:
        fd = w_fileobj.direct_fileno()
        if fd < 0:
            raise oefmt(space.w_ValueError, "file has no OS file descriptor")
        try:
            w_fileobj.cffi_fileobj = CffiFileObj(fd, w_fileobj.mode)
        except OSError as e:
            raise wrap_oserror(space, e)
    return rffi.cast(rffi.CCHARP, w_fileobj.cffi_fileobj.llf)
示例#42
0
def get_osfhandle(space, fd):
    """get_osfhandle()

    Return the handle corresponding to the file descriptor (windows only)
    """
    from rpython.rlib import rwin32  # Windows only
    try:
        ret = rwin32.get_osfhandle(fd)
        return space.newint(rffi.cast(rffi.INT, ret))
    except OSError as e:
        raise wrap_oserror(space, e)
示例#43
0
    def read_w(self, space, w_size=None):
        self._check_closed(space)
        self._check_readable(space)
        size = convert_size(space, w_size)

        if size < 0:
            return self.readall_w(space)

        try:
            s = os.read(self.fd, size)
        except OSError, e:
            raise wrap_oserror(space, e, exception_name='w_IOError')
示例#44
0
def descr_new(space, w_subtype, kind, value, maxvalue):
    if kind != RECURSIVE_MUTEX and kind != SEMAPHORE:
        raise OperationError(space.w_ValueError,
                             space.wrap("unrecognized kind"))

    counter = space.fromcache(CounterState).getCount()
    name = "/mp%d-%d" % (os.getpid(), counter)

    try:
        handle = create_semaphore(space, name, value, maxvalue)
    except OSError, e:
        raise wrap_oserror(space, e)
    def read_w(self, space, w_size=None):
        self._check_closed(space)
        self._check_readable(space)
        size = convert_size(space, w_size)

        if size < 0:
            return self.readall_w(space)

        while True:
            try:
                s = os.read(self.fd, size)
                break
            except OSError as e:
                if e.errno == errno.EAGAIN:
                    return space.w_None
                wrap_oserror(space,
                             e,
                             exception_name='w_IOError',
                             eintr_retry=True)

        return space.newbytes(s)
示例#46
0
    def truncate_w(self, space, w_size=None):
        self._check_closed(space)
        self._check_writable(space)
        if space.is_none(w_size):
            w_size = self.tell_w(space)

        try:
            self._truncate(space.r_longlong_w(w_size))
        except OSError as e:
            raise wrap_oserror(space, e, exception_name='w_IOError')

        return w_size
示例#47
0
def setgroups(space, w_list):
    """ setgroups(list)

    Set the groups of the current process to list.
    """
    list = []
    for w_gid in space.unpackiterable(w_list):
        list.append(space.c_uid_t_w(w_gid))
    try:
        os.setgroups(list[:])
    except OSError as e:
        raise wrap_oserror(space, e)
示例#48
0
def fork(space):
    run_fork_hooks('before', space)

    try:
        pid = os.fork()
    except OSError, e:
        try:
            run_fork_hooks('parent', space)
        except:
            # Don't clobber the OSError if the fork failed
            pass
        raise wrap_oserror(space, e)
示例#49
0
def getresgid(space):
    """ getresgid() -> (rgid, egid, sgid)

    Get tuple of the current process's real, effective, and saved group ids.
    """
    try:
        (rgid, egid, sgid) = os.getresgid()
    except OSError as e:
        raise wrap_oserror(space, e)
    return space.newtuple([wrap_gid(space, rgid),
                           wrap_gid(space, egid),
                           wrap_gid(space, sgid)])
示例#50
0
    def mmap(space,
             fileno,
             length,
             flags=rmmap.MAP_SHARED,
             prot=rmmap.PROT_WRITE | rmmap.PROT_READ,
             access=rmmap._ACCESS_DEFAULT):

        try:
            return space.wrap(
                W_MMap(space, rmmap.mmap(fileno, length, flags, prot, access)))
        except OSError, e:
            raise wrap_oserror(space, e, 'w_EnvironmentError')
示例#51
0
    def _close(self, space):
        if self.fd < 0:
            return
        fd = self.fd
        self.fd = -1

        try:
            os.close(fd)
        except OSError as e:
            raise wrap_oserror(space, e,
                               w_exception_class=space.w_IOError,
                               eintr_retry=False)
示例#52
0
    def truncate_w(self, space, w_size=None):
        self._check_closed(space)
        self._check_writable(space)
        if space.is_none(w_size):
            w_size = self.tell_w(space)

        try:
            self._truncate(space.r_longlong_w(w_size))
        except OSError as e:
            raise wrap_oserror(space, e, w_exception_class=space.w_IOError,
                               eintr_retry=False)

        return w_size
示例#53
0
def utime(space, 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:
            os.utime(path, None)
            return
        except OSError, e:
            raise wrap_oserror(space, e)
示例#54
0
 def modify(self, space, w_fd, events):
     """
     Modify an already registered file descriptor.
     fd -- either an integer, or an object with a fileno() method returning an
       int.
     events -- an optional bitmask describing the type of events to check for
     """
     fd = space.c_filedescriptor_w(w_fd)
     if fd not in self.fddict:
         raise wrap_oserror(space,
                            OSError(errno.ENOENT, "poll.modify"),
                            w_exception_class=space.w_IOError)
     self.fddict[fd] = events
示例#55
0
def test_wrap_oserror():
    class FakeSpace:
        w_OSError = [OSError]
        w_EnvironmentError = [EnvironmentError]
        w_None = None

        def wrap(self, obj, lgt=-1):
            return [obj]

        newint = newtext = newfilename = wrap

        def call_function(self, exc, w_errno, w_msg, w_filename=None, *args):
            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",
                     w_exception_class=space.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"])
示例#56
0
    def write_w(self, space, w_data):
        self._check_closed(space)
        self._check_writable(space)
        data = space.getarg_w('s*', w_data).as_str()

        try:
            n = os.write(self.fd, data)
        except OSError as e:
            if e.errno == errno.EAGAIN:
                return space.w_None
            raise wrap_oserror(space, e, w_exception_class=space.w_IOError)

        return space.newint(n)
示例#57
0
 def __init__(self, space, name, mode):
     self.flags = libffi.FUNCFLAG_CDECL
     self.space = space
     if name is None:
         self.name = "<None>"
     else:
         self.name = name
     try:
         self.cdll = libffi.CDLL(name, mode)
     except DLOpenError as e:
         raise wrap_dlopenerror(space, e, self.name)
     except OSError as e:
         raise wrap_oserror(space, e)
示例#58
0
 def _sendall(self, space, message, size):
     while size > 0:
         # XXX inefficient
         data = rffi.charpsize2str(message, size)
         try:
             count = self.WRITE(data)
         except OSError, e:
             if e.errno == EINTR:
                 space.getexecutioncontext().checksignals()
                 continue
             raise wrap_oserror(space, e)
         size -= count
         message = rffi.ptradd(message, count)
示例#59
0
    def readinto_w(self, space, w_buffer):
        self._check_closed(space)
        self._check_readable(space)
        rwbuffer = space.getarg_w('w*', w_buffer)
        length = rwbuffer.getlength()

        target_address = lltype.nullptr(rffi.CCHARP.TO)
        if length > 64:
            try:
                target_address = rwbuffer.get_raw_address()
            except ValueError:
                pass

        if not target_address:
            # unoptimized case
            try:
                buf = os.read(self.fd, length)
            except OSError as e:
                if e.errno == errno.EAGAIN:
                    return space.w_None
                raise wrap_oserror(space, e,
                                   exception_name='w_IOError')
            rwbuffer.setslice(0, buf)
            return space.newint(len(buf))
        else:
            # optimized case: reading more than 64 bytes into a rwbuffer
            # with a valid raw address
            got = c_read(self.fd, target_address, length)
            keepalive_until_here(rwbuffer)
            got = rffi.cast(lltype.Signed, got)
            if got >= 0:
                return space.newint(got)
            else:
                err = get_saved_errno()
                if err == errno.EAGAIN:
                    return space.w_None
                e = OSError(err, "read failed")
                raise wrap_oserror(space, e, exception_name='w_IOError')
 def rebuild(space, w_cls, w_handle, kind, maxvalue, name):
     #
     if sys_platform != 'win32' and name is not None:
         # like CPython, in this case ignore 'w_handle'
         try:
             handle = reopen_semaphore(name)
         except OSError as e:
             raise wrap_oserror(space, e)
     else:
         handle = handle_w(space, w_handle)
     #
     self = space.allocate_instance(W_SemLock, w_cls)
     self.__init__(space, handle, kind, maxvalue, name)
     return self