Generate a list of candidate temporary directories which _get_default_tempdir will try.
()
| 155 | return ''.join(self.rng.choices(self.characters, k=8)) |
| 156 | |
| 157 | def _candidate_tempdir_list(): |
| 158 | """Generate a list of candidate temporary directories which |
| 159 | _get_default_tempdir will try.""" |
| 160 | |
| 161 | dirlist = [] |
| 162 | |
| 163 | # First, try the environment. |
| 164 | for envname in 'TMPDIR', 'TEMP', 'TMP': |
| 165 | dirname = _os.getenv(envname) |
| 166 | if dirname: dirlist.append(dirname) |
| 167 | |
| 168 | # Failing that, try OS-specific locations. |
| 169 | if _os.name == 'nt': |
| 170 | dirlist.extend([ _os.path.expanduser(r'~\AppData\Local\Temp'), |
| 171 | _os.path.expandvars(r'%SYSTEMROOT%\Temp'), |
| 172 | r'c:\temp', r'c:\tmp', r'\temp', r'\tmp' ]) |
| 173 | else: |
| 174 | dirlist.extend([ '/tmp', '/var/tmp', '/usr/tmp' ]) |
| 175 | |
| 176 | # As a last resort, the current directory. |
| 177 | try: |
| 178 | dirlist.append(_os.getcwd()) |
| 179 | except (AttributeError, OSError): |
| 180 | dirlist.append(_os.curdir) |
| 181 | |
| 182 | return dirlist |
| 183 | |
| 184 | def _get_default_tempdir(dirlist=None): |
| 185 | """Calculate the default directory to use for temporary files. |
no test coverage detected
searching dependent graphs…