MCPcopy Index your code
hub / github.com/RustPython/RustPython / _iterdir

Function _iterdir

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

Source from the content-addressed store, hash-verified

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

Callers 1

_listdirFunction · 0.85

Calls 6

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

Tested by

no test coverage detected