Skip to content

Commit bfaf824

Browse files
authored
Merge pull request #2514 from deantvv/os-closerange
Implement os.closerange
2 parents 22322fa + 974ed85 commit bfaf824

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

Lib/test/test_os.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,6 @@ def test_access(self):
159159
os.close(f)
160160
self.assertTrue(os.access(support.TESTFN, os.W_OK))
161161

162-
# TODO: RUSTPYTHON (AttributeError: module 'os' has no attribute 'dup')
163-
@unittest.expectedFailure
164162
def test_closerange(self):
165163
first = os.open(support.TESTFN, os.O_CREAT|os.O_RDWR)
166164
# We must allocate two consecutive file descriptors, otherwise
@@ -1625,8 +1623,6 @@ def test_urandom_failure(self):
16251623
"""
16261624
assert_python_ok('-c', code)
16271625

1628-
# TODO: RUSTPYTHON
1629-
@unittest.expectedFailure
16301626
def test_urandom_fd_closed(self):
16311627
# Issue #21207: urandom() should reopen its fd to /dev/urandom if
16321628
# closed.
@@ -1641,8 +1637,6 @@ def test_urandom_fd_closed(self):
16411637
"""
16421638
rc, out, err = assert_python_ok('-Sc', code)
16431639

1644-
# TODO: RUSTPYTHON
1645-
@unittest.expectedFailure
16461640
def test_urandom_fd_reopened(self):
16471641
# Issue #21207: urandom() should detect its fd to /dev/urandom
16481642
# changed to something else, and reopen it.

vm/src/stdlib/os.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,13 @@ mod _os {
332332
rust_file(fileno);
333333
}
334334

335+
#[pyfunction]
336+
fn closerange(fd_low: i64, fd_high: i64) {
337+
for fileno in fd_low..fd_high {
338+
close(fileno);
339+
}
340+
}
341+
335342
#[cfg(any(unix, windows, target_os = "wasi"))]
336343
#[pyfunction]
337344
pub(crate) fn open(

0 commit comments

Comments
 (0)