Staging
v0.5.1
https://github.com/python/cpython
Revision caa63808861d4e92d4dc1005fc01de0f2e4a8fd0 authored by Guido van Rossum on 12 January 1995, 11:45:45 UTC, committed by Guido van Rossum on 12 January 1995, 11:45:45 UTC
use the new names exclusively, and the linker will see the new names.
Files that import "Python.h" also only see the new names.  Files that
import "allobjects.h" will continue to be able to use the old names,
due to the inclusion (in allobjects.h) of "rename2.h".
1 parent 94390ec
Raw File
Tip revision: caa63808861d4e92d4dc1005fc01de0f2e4a8fd0 authored by Guido van Rossum on 12 January 1995, 11:45:45 UTC
The great renaming, phase two: all header files have been updated to
Tip revision: caa6380
tempfile.py
# 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 os


# Parameters that the caller may set to override the defaults

tempdir = None
template = None


# 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

counter = 0


# User-callable function to return a unique temporary file name

def mktemp():
	global counter
	dir = gettempdir()
	pre = gettempprefix()
	while 1:
		counter = counter + 1
		file = os.path.join(dir, pre + `counter`)
		if not os.path.exists(file):
			return file
back to top