Пример #1
0
def test_dup_dup2_non_inheritable():
    for preset in [False, True]:
        fd1, fd2 = os.pipe()
        rposix.set_inheritable(fd1, preset)
        rposix.set_inheritable(fd2, preset)
        fd3 = rposix.dup(fd1, True)
        assert rposix.get_inheritable(fd3) == True
        fd4 = rposix.dup(fd1, False)
        assert rposix.get_inheritable(fd4) == False
        rposix.dup2(fd2, fd4, False)
        assert rposix.get_inheritable(fd4) == False
        rposix.dup2(fd2, fd3, True)
        assert rposix.get_inheritable(fd3) == True
        os.close(fd1)
        os.close(fd2)
        os.close(fd3)
        os.close(fd4)
Пример #2
0
def test_dup_dup2_non_inheritable():
    for preset in [False, True]:
        fd1, fd2 = os.pipe()
        rposix.set_inheritable(fd1, preset)
        rposix.set_inheritable(fd2, preset)
        fd3 = rposix.dup(fd1, True)
        assert rposix.get_inheritable(fd3) == True
        fd4 = rposix.dup(fd1, False)
        assert rposix.get_inheritable(fd4) == False
        rposix.dup2(fd2, fd4, False)
        assert rposix.get_inheritable(fd4) == False
        rposix.dup2(fd2, fd3, True)
        assert rposix.get_inheritable(fd3) == True
        os.close(fd1)
        os.close(fd2)
        os.close(fd3)
        os.close(fd4)
Пример #3
0
 def entry_point(argv):
     fd = rposix.open("/tmp/foobar", os.O_RDONLY, 0777)
     assert fd == 77
     fd2 = rposix.dup(fd)
     assert fd2 == 78
     return 0
Пример #4
0
 def entry_point(argv):
     fd = rposix.open("/tmp/foobar", os.O_RDONLY, 0777)
     assert fd == 77
     fd2 = rposix.dup(fd)
     assert fd2 == 78
     return 0
Пример #5
0
def scandir(space, path=None):
    "scandir(path='.') -> iterator of DirEntry objects for given path"
    try:
        space._try_buffer_w(path.w_path, space.BUF_FULL_RO)
    except BufferInterfaceNotFound:
        as_bytes = (path.as_unicode is None)
        result_is_bytes = False
    else:
        as_bytes = True
        result_is_bytes = True
    if path.as_fd != -1:
        if not rposix.HAVE_FDOPENDIR:
            # needed for translation, in practice this is dead code
            raise oefmt(space.w_TypeError,
                        "scandir: illegal type for path argument")
        try:
            dirfd = rposix.dup(path.as_fd, inheritable=False)
        except OSError as e:
            raise wrap_oserror(space, e, eintr_retry=False)
        dirp = rposix.c_fdopendir(dirfd)
        if not dirp:
            rposix.c_close(dirfd)
            e = rposix.get_saved_errno()
            if e == ENOTDIR:
                w_type = space.w_NotADirectoryError
            else:
                w_type = space.w_ValueError
            raise oefmt(w_type, "invalid fd %d", path.as_fd)
        path_prefix = ''
    elif as_bytes:
        path_prefix = path.as_bytes
        try:
            name = path.as_bytes
            dirp = rposix_scandir.opendir(name, len(name))
        except OSError as e:
            raise wrap_oserror2(space,
                                e,
                                space.newbytes(path.as_bytes),
                                eintr_retry=False)
    else:
        w_path = path.w_path
        path_prefix = space.utf8_w(w_path)
        lgt = len(path_prefix)
        try:
            dirp = rposix_scandir.opendir(path_prefix, lgt)
        except OSError as e:
            raise wrap_oserror2(space, e, w_path, eintr_retry=False)
    if not _WIN32:
        if len(path_prefix) > 0 and path_prefix[-1] != '/':
            path_prefix += '/'
        w_path_prefix = space.newbytes(path_prefix)
        if not result_is_bytes:
            w_path_prefix = space.fsdecode(w_path_prefix)
    else:
        if len(path_prefix) > 0 and path_prefix[-1] not in ('\\', '/', ':'):
            path_prefix += '\\'
        if result_is_bytes:
            w_path_prefix = space.newbytes(path_prefix)
        else:
            w_path_prefix = space.newtext(path_prefix)
    if rposix.HAVE_FSTATAT:
        dirfd = rposix.c_dirfd(dirp)
    else:
        dirfd = -1
    return W_ScandirIterator(space, dirp, dirfd, w_path_prefix,
                             result_is_bytes, path.as_fd)