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

Function _mkstemp_inner

Lib/tempfile.py:242–267  ·  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

240
241
242def _mkstemp_inner(dir, pre, suf, flags, output_type):
243 """Code common to mkstemp, TemporaryFile, and NamedTemporaryFile."""
244
245 dir = _os.path.abspath(dir)
246 names = _get_candidate_names()
247 if output_type is bytes:
248 names = map(_os.fsencode, names)
249
250 for seq in range(TMP_MAX):
251 name = next(names)
252 file = _os.path.join(dir, pre + name + suf)
253 _sys.audit("tempfile.mkstemp", file)
254 try:
255 fd = _os.open(file, flags, 0o600)
256 except FileExistsError:
257 continue # try again
258 except PermissionError:
259 # See the comment in mkdtemp().
260 if _os.name == 'nt' and _os.path.isdir(dir) and seq < TMP_MAX - 1:
261 continue
262 else:
263 raise
264 return fd, file
265
266 raise FileExistsError(_errno.EEXIST,
267 "No usable temporary file name found")
268
269def _dont_follow_symlinks(func, path, *args):
270 # 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
abspathMethod · 0.45
joinMethod · 0.45
openMethod · 0.45
isdirMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…