()
Calculate the default directory to use for temporary files.
    This routine should be called exactly once.

    We determine whether or not a candidate temp dir is usable by
    trying to create and write to a file in that directory.  If this
    is successful, the test file is deleted.  To prevent denial of
    service, the name of the test file must be randomized.
Calculate the default directory to use for temporary files.
    This routine should be called exactly once.
Calculate the default directory to use for temporary files . This routine should be called exactly once .
def _get_default_tempdir():
    """Calculate the default directory to use for temporary files.
    This routine should be called exactly once.

    We determine whether or not a candidate temp dir is usable by
    trying to create and write to a file in that directory.  If this
    is successful, the test file is deleted.  To prevent denial of
    service, the name of the test file must be randomized."""

    namer = _RandomNameSequence()
    dirlist = _candidate_tempdir_list()

    for dir in dirlist:
        if dir != _os.curdir:
            dir = _os.path.abspath(dir)
        # Try only a few names per directory.
        for seq in range(100):
            name = next(namer)
            filename = _os.path.join(dir, name)
            try:
                fd = _os.open(filename, _bin_openflags, 0o600)
                try:
                    try:
                        with _io.open(fd, 'wb', closefd=False) as fp:
                            fp.write(b'blat')
                    finally:
                        _os.close(fd)
                finally:
                    _os.unlink(filename)
                return dir
            except FileExistsError:
                pass
            except PermissionError:
                # This exception is thrown when a directory with the chosen name
                # already exists on windows.
                if (_os.name == 'nt' and _os.path.isdir(dir) and
                    _os.access(dir, _os.W_OK)):
                    continue
                break   # no point trying more names in this directory
            except OSError:
                break   # no point trying more names in this directory
    raise FileNotFoundError(_errno.ENOENT,
                            "No usable temporary directory found in %s" %
                            dirlist)
def _get_default_tempdir ( ) : namer = _RandomNameSequence ( ) dirlist = _candidate_tempdir_list ( ) for dir in dirlist : if dir != _os . curdir : dir = _os . path . abspath ( dir ) # Try only a few names per directory. for seq in range ( 100 ) : name = next ( namer ) filename = _os . path . join ( dir , name ) try : fd = _os . open ( filename , _bin_openflags , 0o600 ) try : try : with _io . open ( fd , 'wb' , closefd = False ) as fp : fp . write ( b'blat' ) finally : _os . close ( fd ) finally : _os . unlink ( filename ) return dir except FileExistsError : pass except PermissionError : # This exception is thrown when a directory with the chosen name # already exists on windows. if ( _os . name == 'nt' and _os . path . isdir ( dir ) and _os . access ( dir , _os . W_OK ) ) : continue break # no point trying more names in this directory except OSError : break # no point trying more names in this directory raise FileNotFoundError ( _errno . ENOENT , "No usable temporary directory found in %s" % dirlist )