Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-38144: Add the root_dir and dir_fd parameters in glob.glob(). #16075

Merged
merged 11 commits into from
Jun 18, 2020
Prev Previous commit
Next Next commit
Add glob and iglob in os.supports_dir_fd.
  • Loading branch information
serhiy-storchaka committed Sep 12, 2019
commit 4727de44a2f69ea7b45d7ea7a820a7d994df311b
4 changes: 4 additions & 0 deletions Lib/glob.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,7 @@ def escape(pathname):
else:
pathname = magic_check.sub(r'[\1]', pathname)
return drive + pathname


if {os.open, os.stat} <= os.supports_dir_fd and os.scandir in os.supports_fd:
os.supports_dir_fd.update((glob, iglob))
5 changes: 4 additions & 1 deletion Lib/test/test_glob.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ def setUp(self):
os.symlink(self.norm('broken'), self.norm('sym1'))
os.symlink('broken', self.norm('sym2'))
os.symlink(os.path.join('a', 'bcd'), self.norm('sym3'))
self.dir_fd = os.open(self.tempdir, os.O_RDONLY | os.O_DIRECTORY)
if glob.glob in os.supports_dir_fd:
self.dir_fd = os.open(self.tempdir, os.O_RDONLY | os.O_DIRECTORY)
else:
self.dir_fd = None

def tearDown(self):
if self.dir_fd is not None:
Expand Down