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

Function _mkstemp_inner

Lib/tempfile.py:244–271  ·  view source on GitHub ↗

Code common to mkstemp, TemporaryFile, and NamedTemporaryFile.

(dir, pre, suf, flags, output_type)

Source from the content-addressed store, hash-verified

242
243
244def _mkstemp_inner(dir, pre, suf, flags, output_type):
245 """Code common to mkstemp, TemporaryFile, and NamedTemporaryFile."""
246
247 dir = _os.path.abspath(dir)
248 names = _get_candidate_names()
249 if output_type is bytes:
250 names = map(_os.fsencode, names)
251
252 for seq in range(TMP_MAX):
253 name = next(names)
254 file = _os.path.join(dir, pre + name + suf)
255 _sys.audit("tempfile.mkstemp", file)
256 try:
257 fd = _os.open(file, flags, 0o600)
258 except FileExistsError:
259 continue # try again
260 except PermissionError:
261 # This exception is thrown when a directory with the chosen name
262 # already exists on windows.
263 if (_os.name == 'nt' and _os.path.isdir(dir) and
264 _os.access(dir, _os.W_OK)):
265 continue
266 else:
267 raise
268 return fd, file
269
270 raise FileExistsError(_errno.EEXIST,
271 "No usable temporary file name found")
272
273def _dont_follow_symlinks(func, path, *args):
274 # Pass follow_symlinks=False, unless not supported on this platform.

Callers 2

mkstempFunction · 0.85
openerFunction · 0.85

Calls 5

_get_candidate_namesFunction · 0.85
nextFunction · 0.85
joinMethod · 0.45
openMethod · 0.45
isdirMethod · 0.45

Tested by

no test coverage detected