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

Function _candidate_tempdir_list

Lib/tempfile.py:157–182  ·  view source on GitHub ↗

Generate a list of candidate temporary directories which _get_default_tempdir will try.

()

Source from the content-addressed store, hash-verified

155 return ''.join(self.rng.choices(self.characters, k=8))
156
157def _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
184def _get_default_tempdir(dirlist=None):
185 """Calculate the default directory to use for temporary files.

Callers 1

_get_default_tempdirFunction · 0.85

Calls 3

expanduserMethod · 0.80
appendMethod · 0.45
extendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…