mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Support bytes in os.listdir
This commit is contained in:
1 parent
d95c10c023
commit
a90157c1b7
2 files changed
+13
-3
No files matched your search
@@ -393,6 +393,12 @@ with TestWithTempDir() as tmpdir:
|
||||
|
||||
dir_iter_bytes.close()
|
||||
|
||||
collected_files = os.listdir(tmpdir)
|
||||
assert set(collected_files) == set(expected_files)
|
||||
|
||||
collected_files = os.listdir(tmpdir.encode())
|
||||
assert set(collected_files) == set([file.encode() for file in expected_files ])
|
||||
|
||||
with TestWithTempCurrentDir():
|
||||
os.chdir(tmpdir)
|
||||
with os.scandir() as dir_iter:
|
||||
|
||||
+7
-3
@@ -466,11 +466,15 @@ fn os_rmdir(path: PyStringRef, dir_fd: DirFd, vm: &VirtualMachine) -> PyResult<(
|
||||
fs::remove_dir(path).map_err(|err| convert_io_error(vm, err))
|
||||
}
|
||||
|
||||
fn os_listdir(path: PyStringRef, vm: &VirtualMachine) -> PyResult {
|
||||
let res: PyResult<Vec<PyObjectRef>> = fs::read_dir(path.as_str())
|
||||
fn os_listdir(path: PyPathLike, vm: &VirtualMachine) -> PyResult {
|
||||
let res: PyResult<Vec<PyObjectRef>> = fs::read_dir(&path.path)
|
||||
.map_err(|err| convert_io_error(vm, err))?
|
||||
.map(|entry| match entry {
|
||||
Ok(path) => Ok(vm.ctx.new_str(path.file_name().into_string().unwrap())),
|
||||
Ok(entry_path) => Ok(output_by_mode(
|
||||
entry_path.file_name().into_string().unwrap(),
|
||||
path.mode,
|
||||
vm,
|
||||
)),
|
||||
Err(s) => Err(convert_io_error(vm, s)),
|
||||
})
|
||||
.collect();
|
||||
|
||||
Reference in new issue
Block a user