Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
f4aaf862
Commit
f4aaf862
authored
May 28, 1996
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Be more careful about default temp dir
parent
7a623d7e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
10 deletions
+20
-10
Lib/tempfile.py
Lib/tempfile.py
+20
-10
No files found.
Lib/tempfile.py
View file @
f4aaf862
...
@@ -17,16 +17,26 @@ template = None
...
@@ -17,16 +17,26 @@ template = None
# Function to calculate the directory to use
# Function to calculate the directory to use
def
gettempdir
():
def
gettempdir
():
global
tempdir
global
tempdir
if
tempdir
==
None
:
attempdirs
=
[
'/usr/tmp'
,
'/tmp'
,
os
.
getcwd
(),
os
.
curdir
]
try
:
if
os
.
environ
.
has_key
(
'TMPDIR'
):
tempdir
=
os
.
environ
[
'TMPDIR'
]
attempdirs
.
insert
(
0
,
os
.
environ
[
'TMPDIR'
])
except
(
KeyError
,
AttributeError
):
testfile
=
gettempprefix
()
+
'-*-writetest-*-'
if
os
.
name
==
'posix'
:
for
dir
in
attempdirs
:
tempdir
=
'/usr/tmp'
# XXX Why not /tmp?
try
:
else
:
filename
=
os
.
path
.
join
(
dir
,
testfile
)
tempdir
=
os
.
getcwd
()
# XXX Is this OK?
fp
=
open
(
filename
,
'w'
)
return
tempdir
fp
.
write
(
'blat'
)
fp
.
close
()
os
.
unlink
(
filename
)
tempdir
=
dir
break
except
IOError
:
pass
if
tempdir
is
None
:
msg
=
"Can't find a usable temporary directory amongst "
+
`attempdirs`
raise
IOError
,
msg
return
tempdir
# Function to calculate a prefix of the filename to use
# Function to calculate a prefix of the filename to use
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment