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

Function mkdtemp

Lib/tempfile.py:361–399  ·  view source on GitHub ↗

User-callable function to create and return a unique temporary directory. The return value is the pathname of the directory. Arguments are as for mkstemp, except that the 'text' argument is not accepted. The directory is readable, writable, and searchable only by the creating

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

Source from the content-addressed store, hash-verified

359
360
361def mkdtemp(suffix=None, prefix=None, dir=None):
362 """User-callable function to create and return a unique temporary
363 directory. The return value is the pathname of the directory.
364
365 Arguments are as for mkstemp, except that the 'text' argument is
366 not accepted.
367
368 The directory is readable, writable, and searchable only by the
369 creating user.
370
371 Caller is responsible for deleting the directory when done with it.
372 """
373
374 prefix, suffix, dir, output_type = _sanitize_params(prefix, suffix, dir)
375
376 names = _get_candidate_names()
377 if output_type is bytes:
378 names = map(_os.fsencode, names)
379
380 for seq in range(TMP_MAX):
381 name = next(names)
382 file = _os.path.join(dir, prefix + name + suffix)
383 _sys.audit("tempfile.mkdtemp", file)
384 try:
385 _os.mkdir(file, 0o700)
386 except FileExistsError:
387 continue # try again
388 except PermissionError:
389 # This exception is thrown when a directory with the chosen name
390 # already exists on windows.
391 if (_os.name == 'nt' and _os.path.isdir(dir) and
392 _os.access(dir, _os.W_OK)):
393 continue
394 else:
395 raise
396 return _os.path.abspath(file)
397
398 raise FileExistsError(_errno.EEXIST,
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

Callers 1

__init__Method · 0.85

Calls 6

_sanitize_paramsFunction · 0.85
_get_candidate_namesFunction · 0.85
nextFunction · 0.85
joinMethod · 0.45
mkdirMethod · 0.45
isdirMethod · 0.45

Tested by

no test coverage detected