summaryrefslogtreecommitdiffstats
path: root/Lib/tempfile.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1991-11-12 15:38:08 (GMT)
committerGuido van Rossum <guido@python.org>1991-11-12 15:38:08 (GMT)
commiteee9498b71a10381e5017201ed9d2fcb547d4305 (patch)
tree980a3f0e67dc1eac77d09edf8b4086904dfaa80d /Lib/tempfile.py
parent5478cc68f8699dab10a25b976671ae52a0d8f6a8 (diff)
downloadcpython-eee9498b71a10381e5017201ed9d2fcb547d4305.zip
cpython-eee9498b71a10381e5017201ed9d2fcb547d4305.tar.gz
cpython-eee9498b71a10381e5017201ed9d2fcb547d4305.tar.bz2
Initial revision
Diffstat (limited to 'Lib/tempfile.py')
-rw-r--r--Lib/tempfile.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/Lib/tempfile.py b/Lib/tempfile.py
new file mode 100644
index 0000000..02e73e1
--- /dev/null
+++ b/Lib/tempfile.py
@@ -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