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

Function mktemp

Lib/tempfile.py:401–430  ·  view source on GitHub ↗

User-callable function to return a unique temporary file name. The file is not created. Arguments are similar to mkstemp, except that the 'text' argument is not accepted, and suffix=None, prefix=None and bytes file names are not supported. THIS FUNCTION IS UNSAFE AND SHOULD NO

(suffix="", prefix=template, dir=None)

Source from the content-addressed store, hash-verified

399 "No usable temporary directory name found")
400
401def mktemp(suffix="", prefix=template, dir=None):
402 """User-callable function to return a unique temporary file name. The
403 file is not created.
404
405 Arguments are similar to mkstemp, except that the 'text' argument is
406 not accepted, and suffix=None, prefix=None and bytes file names are not
407 supported.
408
409 THIS FUNCTION IS UNSAFE AND SHOULD NOT BE USED. The file name may
410 refer to a file that did not exist at some point, but by the time
411 you get around to creating it, someone else may have beaten you to
412 the punch.
413 """
414
415## from warnings import warn as _warn
416## _warn("mktemp is a potential security risk to your program",
417## RuntimeWarning, stacklevel=2)
418
419 if dir is None:
420 dir = gettempdir()
421
422 names = _get_candidate_names()
423 for seq in range(TMP_MAX):
424 name = next(names)
425 file = _os.path.join(dir, prefix + name + suffix)
426 if not _exists(file):
427 return file
428
429 raise FileExistsError(_errno.EEXIST,
430 "No usable temporary filename found")
431
432
433class _TemporaryFileCloser:

Callers

nothing calls this directly

Calls 4

gettempdirFunction · 0.85
_get_candidate_namesFunction · 0.85
_existsFunction · 0.70
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…