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)
| 399 | "No usable temporary directory name found") |
| 400 | |
| 401 | def 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 | |
| 433 | class _TemporaryFileCloser: |
nothing calls this directly
no test coverage detected
searching dependent graphs…