Example #1
0
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)
Example #2
0
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)
Example #3
0
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)
            # NOTE: 'result' can be either a list of str or a list of
            # unicodes, depending on the platform
            w_fs_encoding = getfilesystemencoding(space)
            len_result = len(result)
            result_w = [None] * len_result
            for i in range(len_result):
                res = result[i]
                if isinstance(res, str):
                    w_bytes = space.newtext(res)
                    try:
                        w_res = 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
                        w_res = w_bytes
                elif isinstance(res, unicode):
                    w_res = u2utf8(space, res)
                else:
                    assert False
                result_w[i] = w_res
            return space.newlist(result_w)
Example #4
0
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)
            w_fs_encoding = getfilesystemencoding(space)
            len_result = len(result)
            result_w = [None] * len_result
            for i in range(len_result):
                w_bytes = space.wrap(result[i])
                try:
                    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:
Example #5
0
 def f():
     if isinstance(udir.as_unicode(), str):
         _udir = udir.as_unicode()
         _res = ', '
     else:
         _udir = udir
         _res = u', '
     return _res.join(rposix.listdir(_udir))
Example #6
0
 def f():
     if isinstance(udir.as_unicode(), str):
         _udir = udir.as_unicode()
         _res = ', '
     else:
         _udir = udir
         _res = u', '
     return _res.join(rposix.listdir(_udir))
Example #7
0
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)
            w_fs_encoding = getfilesystemencoding(space)
            len_result = len(result)
            result_w = [None] * len_result
            for i in range(len_result):
                w_bytes = space.wrap(result[i])
                try:
                    result_w[i] = space.call_method(w_bytes, "decode",
                                                    w_fs_encoding)
                except OperationError, e:
                    # fall back to the original byte string
                    result_w[i] = w_bytes
            return space.newlist(result_w)
        else:
Example #8
0
 def f():
     return ', '.join(rposix.listdir(udir))
Example #9
0
 def f():
     return ', '.join(rposix.listdir(udir))
Example #10
0
                        w_res = 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
                        w_res = w_bytes
                elif isinstance(res, unicode):
                    w_res = u2utf8(space, res)
                else:
                    assert False
                result_w[i] = w_res
            return space.newlist(result_w)
        else:
            dirname = space.bytes0_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.newint(fd1), space.newint(fd2)])
Example #11
0
            len_result = len(result)
            result_w = [None] * len_result
            for i in range(len_result):
                w_bytes = space.wrap(result[i])
                try:
                    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)