Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
41f9503c
Kaydet (Commit)
41f9503c
authored
Mar 31, 1992
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Mostly rewritten to be more flexible and more portable
./
üst
1a76ef26
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
18 deletions
+41
-18
tempfile.py
Lib/tempfile.py
+41
-18
No files found.
Lib/tempfile.py
Dosyayı görüntüle @
41f9503c
# Temporary file name allocation
#
# XXX This tries to be not UNIX specific, but I don't know beans about
# how to choose a temp directory or filename on MS-DOS or other
# systems so it may have to be changed...
import
posix
import
path
import
os
# Changeable parameters (by clients!)...
tempdir
=
'/usr/tmp'
template
=
'@'
# Parameters that the caller may set to override the defaults
# Use environment variable $TMPDIR to override default tempdir.
tempdir
=
None
template
=
None
if
posix
.
environ
.
has_key
(
'TMPDIR'
):
# XXX Could check that it's a writable directory...
tempdir
=
posix
.
environ
[
'TMPDIR'
]
# Function to calculate the directory to use
def
gettempdir
():
global
tempdir
if
tempdir
==
None
:
try
:
tempdir
=
os
.
environ
[
'TMPDIR'
]
except
(
KeyError
,
AttributeError
):
if
os
.
name
==
'posix'
:
tempdir
=
'/usr/tmp'
# XXX Why not /tmp?
else
:
tempdir
=
os
.
getcwd
()
# XXX Is this OK?
return
tempdir
# Function to calculate a prefix of the filename to use
def
gettempprefix
():
global
template
if
template
==
None
:
if
os
.
name
==
'posix'
:
template
=
'@'
+
`os.getpid()`
+
'.'
else
:
template
=
'tmp'
# XXX might choose a better one
return
template
# Counter for generating unique names
...
...
@@ -21,16 +46,14 @@ if posix.environ.has_key('TMPDIR'):
counter
=
0
# User-callable function
# XXX Should this have a parameter, like C's mktemp()?
# XXX Should we instead use the model of Standard C's tempnam()?
# XXX By all means, avoid a mess with four different functions like C...
# User-callable function to return a unique temporary file name
def
mktemp
():
global
counter
dir
=
gettempdir
()
pre
=
gettempprefix
()
while
1
:
counter
=
counter
+
1
file
=
tempdir
+
'/'
+
template
+
`posix.getpid()`
+
'.'
+
`counter`
if
not
path
.
exists
(
file
):
break
return
file
counter
=
counter
+
1
file
=
os
.
path
.
join
(
dir
,
pre
+
`counter`
)
if
not
os
.
path
.
exists
(
file
):
return
file
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