mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
Initial revision
This commit is contained in:
parent
5478cc68f8
commit
eee9498b71
3 changed files with 190 additions and 0 deletions
32
Lib/tempfile.py
Normal file
32
Lib/tempfile.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
# Temporary file name allocation
|
||||
|
||||
import posix
|
||||
import path
|
||||
|
||||
|
||||
# Changeable parameters (by clients!)...
|
||||
# XXX Should the environment variable $TMPDIR override tempdir?
|
||||
|
||||
tempdir = '/usr/tmp'
|
||||
template = '@'
|
||||
|
||||
|
||||
# Kludge to hold mutable state
|
||||
|
||||
class Struct(): pass
|
||||
G = Struct()
|
||||
G.i = 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...
|
||||
|
||||
def mktemp():
|
||||
while 1:
|
||||
G.i = G.i+1
|
||||
file = tempdir +'/'+ template + `posix.getpid()` +'.'+ `G.i`
|
||||
if not path.exists(file):
|
||||
break
|
||||
return file
|
||||
Loading…
Add table
Add a link
Reference in a new issue