Merge pull request #2514 from deantvv/os-closerange

Implement os.closerange
This commit is contained in:
Noah
2021-03-06 16:12:11 -06:00
committed by GitHub
2 changed files with 7 additions and 6 deletions

View File

@@ -159,8 +159,6 @@ class FileTests(unittest.TestCase):
os.close(f)
self.assertTrue(os.access(support.TESTFN, os.W_OK))
# TODO: RUSTPYTHON (AttributeError: module 'os' has no attribute 'dup')
@unittest.expectedFailure
def test_closerange(self):
first = os.open(support.TESTFN, os.O_CREAT|os.O_RDWR)
# We must allocate two consecutive file descriptors, otherwise
@@ -1625,8 +1623,6 @@ class URandomFDTests(unittest.TestCase):
"""
assert_python_ok('-c', code)
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_urandom_fd_closed(self):
# Issue #21207: urandom() should reopen its fd to /dev/urandom if
# closed.
@@ -1641,8 +1637,6 @@ class URandomFDTests(unittest.TestCase):
"""
rc, out, err = assert_python_ok('-Sc', code)
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_urandom_fd_reopened(self):
# Issue #21207: urandom() should detect its fd to /dev/urandom
# changed to something else, and reopen it.

View File

@@ -332,6 +332,13 @@ mod _os {
rust_file(fileno);
}
#[pyfunction]
fn closerange(fd_low: i64, fd_high: i64) {
for fileno in fd_low..fd_high {
close(fileno);
}
}
#[cfg(any(unix, windows, target_os = "wasi"))]
#[pyfunction]
pub(crate) fn open(