MCPcopy Index your code
hub / github.com/python/cpython / _iterdir

Function _iterdir

Lib/glob.py:164–196  ·  view source on GitHub ↗
(dirname, dir_fd, dironly)

Source from the content-addressed store, hash-verified

162# If dironly is false, yields all file names inside a directory.
163# If dironly is true, yields only directory names.
164def _iterdir(dirname, dir_fd, dironly):
165 try:
166 fd = None
167 fsencode = None
168 if dir_fd is not None:
169 if dirname:
170 fd = arg = os.open(dirname, _dir_open_flags, dir_fd=dir_fd)
171 else:
172 arg = dir_fd
173 if isinstance(dirname, bytes):
174 fsencode = os.fsencode
175 elif dirname:
176 arg = dirname
177 elif isinstance(dirname, bytes):
178 arg = bytes(os.curdir, 'ASCII')
179 else:
180 arg = os.curdir
181 try:
182 with os.scandir(arg) as it:
183 for entry in it:
184 try:
185 if not dironly or entry.is_dir():
186 if fsencode is not None:
187 yield fsencode(entry.name)
188 else:
189 yield entry.name
190 except OSError:
191 pass
192 finally:
193 if fd is not None:
194 os.close(fd)
195 except OSError:
196 return
197
198def _listdir(dirname, dir_fd, dironly):
199 with contextlib.closing(_iterdir(dirname, dir_fd, dironly)) as it:

Callers 1

_listdirFunction · 0.85

Calls 5

fsencodeFunction · 0.85
openMethod · 0.45
scandirMethod · 0.45
is_dirMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…