|
1 | 1 | """Filename globbing utility."""
|
2 | 2 |
|
| 3 | +import contextlib |
3 | 4 | import os
|
4 | 5 | import re
|
5 | 6 | import fnmatch
|
@@ -90,7 +91,7 @@ def _iglob(pathname, root_dir, dir_fd, recursive, dironly):
|
90 | 91 | # takes a literal basename (so it only has to check for its existence).
|
91 | 92 |
|
92 | 93 | def _glob1(dirname, pattern, dir_fd, dironly):
|
93 |
| - names = list(_iterdir(dirname, dir_fd, dironly)) |
| 94 | + names = _listdir(dirname, dir_fd, dironly) |
94 | 95 | if not _ishidden(pattern):
|
95 | 96 | names = (x for x in names if not _ishidden(x))
|
96 | 97 | return fnmatch.filter(names, pattern)
|
@@ -158,9 +159,13 @@ def _iterdir(dirname, dir_fd, dironly):
|
158 | 159 | except OSError:
|
159 | 160 | return
|
160 | 161 |
|
| 162 | +def _listdir(dirname, dir_fd, dironly): |
| 163 | + with contextlib.closing(_iterdir(dirname, dir_fd, dironly)) as it: |
| 164 | + return list(it) |
| 165 | + |
161 | 166 | # Recursively yields relative pathnames inside a literal directory.
|
162 | 167 | def _rlistdir(dirname, dir_fd, dironly):
|
163 |
| - names = list(_iterdir(dirname, dir_fd, dironly)) |
| 168 | + names = _listdir(dirname, dir_fd, dironly) |
164 | 169 | for x in names:
|
165 | 170 | if not _ishidden(x):
|
166 | 171 | yield x
|
|
0 commit comments