Massive changes from SF 589982 (tempfile.py rewrite, by Zack

Weinberg).  This changes all uses of deprecated tempfile functions to
the recommended ones.
This commit is contained in:
Guido van Rossum 2002-08-09 16:38:32 +00:00
parent 830a5151c1
commit 3b0a3293c3
31 changed files with 134 additions and 149 deletions

View file

@ -143,22 +143,17 @@ class RCS:
if message and message[-1] != '\n': if message and message[-1] != '\n':
message = message + '\n' message = message + '\n'
lockflag = "-u" lockflag = "-u"
textfile = None if new:
try: f = tempfile.NamedTemporaryFile()
if new: f.write(message)
textfile = tempfile.mktemp() f.flush()
f = open(textfile, 'w') cmd = 'ci %s%s -t%s %s %s' % \
f.write(message) (lockflag, rev, f.name, otherflags, name)
f.close() else:
cmd = 'ci %s%s -t%s %s %s' % \ message = regsub.gsub('\([\\"$`]\)', '\\\\\\1', message)
(lockflag, rev, textfile, otherflags, name) cmd = 'ci %s%s -m"%s" %s %s' % \
else: (lockflag, rev, message, otherflags, name)
message = regsub.gsub('\([\\"$`]\)', '\\\\\\1', message) return self._system(cmd)
cmd = 'ci %s%s -m"%s" %s %s' % \
(lockflag, rev, message, otherflags, name)
return self._system(cmd)
finally:
if textfile: self._remove(textfile)
# --- Exported support methods --- # --- Exported support methods ---

View file

@ -172,17 +172,13 @@ class MyFile(File):
if self.lsum == sum: if self.lsum == sum:
return return
import tempfile import tempfile
tfn = tempfile.mktemp() tf = tempfile.NamedTemporaryFile()
try: tf.write(data)
tf = open(tfn, 'w') tf.flush()
tf.write(data) print 'diff %s -r%s %s' % (flags, rev, fn)
tf.close() sts = os.system('diff %s %s %s' % (flags, tf.name, fn))
print 'diff %s -r%s %s' % (flags, rev, fn) if sts:
sts = os.system('diff %s %s %s' % (flags, tfn, fn)) print '='*70
if sts:
print '='*70
finally:
remove(tfn)
def commitcheck(self): def commitcheck(self):
return self.action() != 'C' return self.action() != 'C'

View file

@ -102,17 +102,13 @@ def diff(x, copts, fn):
flags = flags + ' ' + o + a flags = flags + ' ' + o + a
flags = flags[1:] flags = flags[1:]
data = x.get(fn) data = x.get(fn)
tfn = tempfile.mktemp() tf = tempfile.NamedTemporaryFile()
try: tf.write(data)
tf = open(tfn, 'w') tf.flush()
tf.write(data) print 'diff %s -r%s %s' % (flags, x.head(fn), fn)
tf.close() sts = os.system('diff %s %s %s' % (flags, tf.name, fn))
print 'diff %s -r%s %s' % (flags, x.head(fn), fn) if sts:
sts = os.system('diff %s %s %s' % (flags, tfn, fn)) print '='*70
if sts:
print '='*70
finally:
remove(tfn)
def same(x, copts, fn, data = None): def same(x, copts, fn, data = None):
if data is None: if data is None:

View file

@ -120,19 +120,11 @@ for line in SCRIPT:
program = program + (string.joinfields(epilogue, '\n') + '\n') program = program + (string.joinfields(epilogue, '\n') + '\n')
import tempfile import tempfile
tfn = tempfile.mktemp() fp = tempfile.NamedTemporaryFile()
try: fp.write(program)
fp = open(tfn, 'w') fp.flush()
fp.write(program) if DFLAG:
fp.close() import pdb
if DFLAG: pdb.run('execfile(' + `tfn` + ')')
import pdb else:
pdb.run('execfile(' + `tfn` + ')') execfile(tfn)
else:
execfile(tfn)
finally:
import os
try:
os.unlink(tfn)
except:
pass

View file

@ -193,10 +193,10 @@ class Hook:
if self.logdir is not None: if self.logdir is not None:
import os, tempfile import os, tempfile
name = tempfile.mktemp(['.html', '.txt'][text]) (fd, name) = tempfile.mkstemp(suffix=['.html', '.txt'][text],
path = os.path.join(self.logdir, os.path.basename(name)) dir=self.logdir)
try: try:
file = open(path, 'w') file = os.fdopen(fd, 'w')
file.write(doc) file.write(doc)
file.close() file.close()
msg = '<p> %s contains the description of this error.' % path msg = '<p> %s contains the description of this error.' % path

View file

@ -130,8 +130,9 @@ class bdist_wininst (Command):
# And make an archive relative to the root of the # And make an archive relative to the root of the
# pseudo-installation tree. # pseudo-installation tree.
from tempfile import mktemp from tempfile import NamedTemporaryFile
archive_basename = mktemp() arc = NamedTemporaryFile(".zip")
archive_basename = arc.name[:-4]
fullname = self.distribution.get_fullname() fullname = self.distribution.get_fullname()
arcname = self.make_archive(archive_basename, "zip", arcname = self.make_archive(archive_basename, "zip",
root_dir=self.bdist_dir) root_dir=self.bdist_dir)
@ -139,7 +140,7 @@ class bdist_wininst (Command):
self.create_exe(arcname, fullname, self.bitmap) self.create_exe(arcname, fullname, self.bitmap)
# remove the zip-file again # remove the zip-file again
log.debug("removing temporary file '%s'", arcname) log.debug("removing temporary file '%s'", arcname)
os.remove(arcname) arc.close()
if not self.keep_temp: if not self.keep_temp:
remove_tree(self.bdist_dir, dry_run=self.dry_run) remove_tree(self.bdist_dir, dry_run=self.dry_run)

View file

@ -359,11 +359,11 @@ def byte_compile (py_files,
# "Indirect" byte-compilation: write a temporary script and then # "Indirect" byte-compilation: write a temporary script and then
# run it with the appropriate flags. # run it with the appropriate flags.
if not direct: if not direct:
from tempfile import mktemp from tempfile import mkstemp
script_name = mktemp(".py") (script_fd, script_name) = mkstemp(".py")
log.info("writing byte-compilation script '%s'", script_name) log.info("writing byte-compilation script '%s'", script_name)
if not dry_run: if not dry_run:
script = open(script_name, "w") script = os.fdopen(script_fd, "w")
script.write("""\ script.write("""\
from distutils.util import byte_compile from distutils.util import byte_compile

View file

@ -8,12 +8,10 @@ import test.pystone
if sys.argv[1:]: if sys.argv[1:]:
logfile = sys.argv[1] logfile = sys.argv[1]
cleanup = 0
else: else:
import tempfile import tempfile
logfile = tempfile.mktemp() logf = tempfile.NamedTemporaryFile()
cleanup = 1 logfile = logf.name
p = hotshot.Profile(logfile) p = hotshot.Profile(logfile)
benchtime, stones = p.runcall(test.pystone.pystones) benchtime, stones = p.runcall(test.pystone.pystones)
@ -24,8 +22,6 @@ print "Pystone(%s) time for %d passes = %g" % \
print "This machine benchmarks at %g pystones/second" % stones print "This machine benchmarks at %g pystones/second" % stones
stats = hotshot.stats.load(logfile) stats = hotshot.stats.load(logfile)
if cleanup:
os.unlink(logfile)
stats.strip_dirs() stats.strip_dirs()
stats.sort_stats('time', 'calls') stats.sort_stats('time', 'calls')
try: try:

View file

@ -202,8 +202,8 @@ def pipeto(input, command):
pipe.close() pipe.close()
def pipethrough(input, command, output): def pipethrough(input, command, output):
tempname = tempfile.mktemp() (fd, tempname) = tempfile.mkstemp()
temp = open(tempname, 'w') temp = os.fdopen(fd, 'w')
copyliteral(input, temp) copyliteral(input, temp)
temp.close() temp.close()
pipe = os.popen(command + ' <' + tempname, 'r') pipe = os.popen(command + ' <' + tempname, 'r')

View file

@ -225,7 +225,8 @@ def makepipeline(infile, steps, outfile):
lkind = list[i-1][2] lkind = list[i-1][2]
rkind = list[i][2] rkind = list[i][2]
if lkind[1] == 'f' or rkind[0] == 'f': if lkind[1] == 'f' or rkind[0] == 'f':
temp = tempfile.mktemp() (fd, temp) = tempfile.mkstemp()
os.close(fd)
garbage.append(temp) garbage.append(temp)
list[i-1][-1] = list[i][0] = temp list[i-1][-1] = list[i][0] = temp
# #

View file

@ -70,7 +70,8 @@ def torgb(filename):
def _torgb(filename, temps): def _torgb(filename, temps):
if filename[-2:] == '.Z': if filename[-2:] == '.Z':
fname = tempfile.mktemp() (fd, fname) = tempfile.mkstemp()
os.close(fd)
temps.append(fname) temps.append(fname)
sts = uncompress.copy(filename, fname) sts = uncompress.copy(filename, fname)
if sts: if sts:
@ -91,7 +92,8 @@ def _torgb(filename, temps):
if ftype is None or not table.has_key(ftype): if ftype is None or not table.has_key(ftype):
raise error, \ raise error, \
filename + ': unsupported image file type ' + `ftype` filename + ': unsupported image file type ' + `ftype`
temp = tempfile.mktemp() (fd, temp) = tempfile.mktemp()
os.close(fd)
sts = table[ftype].copy(fname, temp) sts = table[ftype].copy(fname, temp)
if sts: if sts:
raise error, filename + ': conversion to rgb failed' raise error, filename + ': conversion to rgb failed'

View file

@ -70,7 +70,8 @@ def torgb(filename):
def _torgb(filename, temps): def _torgb(filename, temps):
if filename[-2:] == '.Z': if filename[-2:] == '.Z':
fname = tempfile.mktemp() (fd, fname) = tempfile.mkstemp()
os.close(fd)
temps.append(fname) temps.append(fname)
sts = uncompress.copy(filename, fname) sts = uncompress.copy(filename, fname)
if sts: if sts:
@ -91,7 +92,8 @@ def _torgb(filename, temps):
if ftype is None or not table.has_key(ftype): if ftype is None or not table.has_key(ftype):
raise error, \ raise error, \
filename + ': unsupported image file type ' + `ftype` filename + ': unsupported image file type ' + `ftype`
temp = tempfile.mktemp() (fd, temp) = tempfile.mktemp()
os.close(fd)
sts = table[ftype].copy(fname, temp) sts = table[ftype].copy(fname, temp)
if sts: if sts:
raise error, filename + ': conversion to rgb failed' raise error, filename + ': conversion to rgb failed'

View file

@ -1203,8 +1203,8 @@ def getpager():
return lambda text: pipepager(text, 'less') return lambda text: pipepager(text, 'less')
import tempfile import tempfile
filename = tempfile.mktemp() (fd, filename) = tempfile.mkstemp()
open(filename, 'w').close() os.close(fd)
try: try:
if hasattr(os, 'system') and os.system('more %s' % filename) == 0: if hasattr(os, 'system') and os.system('more %s' % filename) == 0:
return lambda text: pipepager(text, 'more') return lambda text: pipepager(text, 'more')
@ -1229,8 +1229,8 @@ def pipepager(text, cmd):
def tempfilepager(text, cmd): def tempfilepager(text, cmd):
"""Page through text by invoking a program on a temporary file.""" """Page through text by invoking a program on a temporary file."""
import tempfile import tempfile
filename = tempfile.mktemp() (fd, filename) = tempfile.mkstemp()
file = open(filename, 'w') file = os.fdopen(fd, 'w')
file.write(text) file.write(text)
file.close() file.close()
try: try:

View file

@ -1,5 +1,5 @@
import unittest import unittest
from test.test_support import TestFailed, have_unicode from test.test_support import TestFailed, have_unicode, TESTFN
class C: class C:
def __cmp__(self, other): def __cmp__(self, other):
@ -269,17 +269,19 @@ class AbstractPickleTests(unittest.TestCase):
class AbstractPickleModuleTests(unittest.TestCase): class AbstractPickleModuleTests(unittest.TestCase):
def test_dump_closed_file(self): def test_dump_closed_file(self):
import tempfile, os import os
fn = tempfile.mktemp() f = open(TESTFN, "w")
f = open(fn, "w") try:
f.close() f.close()
self.assertRaises(ValueError, self.module.dump, 123, f) self.assertRaises(ValueError, self.module.dump, 123, f)
os.remove(fn) finally:
os.remove(TESTFN)
def test_load_closed_file(self): def test_load_closed_file(self):
import tempfile, os import os
fn = tempfile.mktemp() f = open(TESTFN, "w")
f = open(fn, "w") try:
f.close() f.close()
self.assertRaises(ValueError, self.module.dump, 123, f) self.assertRaises(ValueError, self.module.dump, 123, f)
os.remove(fn) finally:
os.remove(TESTFN)

View file

@ -6,11 +6,10 @@
import os import os
import unittest import unittest
import anydbm import anydbm
import tempfile
import glob import glob
from test import test_support from test import test_support
_fname = tempfile.mktemp() _fname = test_support.TESTFN
def _delete_files(): def _delete_files():
# we don't know the precise name the underlying database uses # we don't know the precise name the underlying database uses

View file

@ -6,7 +6,6 @@
""" """
import binhex import binhex
import os import os
import tempfile
import unittest import unittest
from test import test_support from test import test_support
@ -14,8 +13,8 @@ from test import test_support
class BinHexTestCase(unittest.TestCase): class BinHexTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
self.fname1 = tempfile.mktemp() self.fname1 = test_support.TESTFN + "1"
self.fname2 = tempfile.mktemp() self.fname2 = test_support.TESTFN + "2"
def tearDown(self): def tearDown(self):
try: os.unlink(self.fname1) try: os.unlink(self.fname1)

View file

@ -5,8 +5,7 @@
import os import os
import bsddb import bsddb
import dbhash # Just so we know it's imported import dbhash # Just so we know it's imported
import tempfile from test.test_support import verbose, verify, TESTFN
from test.test_support import verbose, verify
def test(openmethod, what, ondisk=1): def test(openmethod, what, ondisk=1):
@ -14,7 +13,7 @@ def test(openmethod, what, ondisk=1):
print '\nTesting: ', what, (ondisk and "on disk" or "in memory") print '\nTesting: ', what, (ondisk and "on disk" or "in memory")
if ondisk: if ondisk:
fname = tempfile.mktemp() fname = TESTFN
else: else:
fname = None fname = None
f = openmethod(fname, 'c') f = openmethod(fname, 'c')

View file

@ -24,10 +24,17 @@ class CommandTests(unittest.TestCase):
self.assertEquals(getoutput('echo xyzzy'), 'xyzzy') self.assertEquals(getoutput('echo xyzzy'), 'xyzzy')
self.assertEquals(getstatusoutput('echo xyzzy'), (0, 'xyzzy')) self.assertEquals(getstatusoutput('echo xyzzy'), (0, 'xyzzy'))
# we use mktemp in the next line to get a filename which we # we use mkdtemp in the next line to create an empty directory
# _know_ won't exist. This is guaranteed to fail. # under our exclusive control; from that, we can invent a pathname
status, output = getstatusoutput('cat ' + tempfile.mktemp()) # that we _know_ won't exist. This is guaranteed to fail.
self.assertNotEquals(status, 0) try:
dir = tempfile.mkdtemp()
name = os.path.join(dir, "foo")
status, output = getstatusoutput('cat ' + name)
self.assertNotEquals(status, 0)
finally:
os.rmdir(dir)
def test_getstatus(self): def test_getstatus(self):
# This pattern should match 'ls -ld /.' on any posix # This pattern should match 'ls -ld /.' on any posix

View file

@ -6,10 +6,9 @@
import os import os
import unittest import unittest
import dumbdbm import dumbdbm
import tempfile
from test import test_support from test import test_support
_fname = tempfile.mktemp() _fname = test_support.TESTFN
def _delete_files(): def _delete_files():
for ext in [".dir", ".dat", ".bak"]: for ext in [".dir", ".dat", ".bak"]:

View file

@ -1,8 +1,8 @@
from test.test_support import verify from test.test_support import verify, TESTFN
import sys, os import sys, os
import gzip, tempfile import gzip
filename = tempfile.mktemp() filename = TESTFN
data1 = """ int length=DEFAULTALLOC, err = Z_OK; data1 = """ int length=DEFAULTALLOC, err = Z_OK;
PyObject *RetVal; PyObject *RetVal;

View file

@ -1,5 +1,5 @@
import netrc, os, tempfile, unittest import netrc, os, unittest
from test import test_support from test import test_support
TEST_NETRC = """ TEST_NETRC = """
@ -17,7 +17,7 @@ default login log2 password pass2
""" """
temp_filename = tempfile.mktemp() temp_filename = test_support.TESTFN
class NetrcTestCase(unittest.TestCase): class NetrcTestCase(unittest.TestCase):

View file

@ -8,7 +8,8 @@ from test.test_support import verify, verbose, TestFailed
# Helpers to create and destroy hierarchies. # Helpers to create and destroy hierarchies.
def mkhier(root, descr): def mkhier(root, descr):
mkdir(root) if not os.path.isdir(root):
mkdir(root)
for name, contents in descr: for name, contents in descr:
comps = name.split() comps = name.split()
fullname = root fullname = root
@ -52,18 +53,17 @@ def fixdir(lst):
# Helper to run a test # Helper to run a test
def runtest(hier, code): def runtest(hier, code):
root = tempfile.mktemp() root = tempfile.mkdtemp()
mkhier(root, hier) mkhier(root, hier)
savepath = sys.path[:] savepath = sys.path[:]
codefile = tempfile.mktemp() codefile = tempfile.NamedTemporaryFile()
f = open(codefile, "w") codefile.write(code)
f.write(code) codefile.flush()
f.close()
try: try:
sys.path.insert(0, root) sys.path.insert(0, root)
if verbose: print "sys.path =", sys.path if verbose: print "sys.path =", sys.path
try: try:
execfile(codefile, globals(), {}) execfile(codefile.name, globals(), {})
except: except:
traceback.print_exc(file=sys.stdout) traceback.print_exc(file=sys.stdout)
finally: finally:
@ -72,7 +72,6 @@ def runtest(hier, code):
cleanout(root) cleanout(root)
except (os.error, IOError): except (os.error, IOError):
pass pass
os.remove(codefile)
# Test descriptions # Test descriptions

View file

@ -17,8 +17,7 @@ class TestImport(unittest.TestCase):
del sys.modules[module_name] del sys.modules[module_name]
def setUp(self): def setUp(self):
self.test_dir = tempfile.mktemp() self.test_dir = tempfile.mkdtemp()
os.mkdir(self.test_dir)
sys.path.append(self.test_dir) sys.path.append(self.test_dir)
self.package_dir = os.path.join(self.test_dir, self.package_dir = os.path.join(self.test_dir,
self.package_name) self.package_name)

View file

@ -124,8 +124,7 @@ except uu.Error, e:
verify(str(e) == 'No valid begin line found in input file') verify(str(e) == 'No valid begin line found in input file')
# Test to verify that decode() will refuse to overwrite an existing file # Test to verify that decode() will refuse to overwrite an existing file
import tempfile outfile = TESTFN + "out"
outfile = tempfile.mktemp()
inp = StringIO('Here is a message to be uuencoded') inp = StringIO('Here is a message to be uuencoded')
out = StringIO() out = StringIO()
uu.encode(inp, out, outfile) uu.encode(inp, out, outfile)

View file

@ -1,5 +1,5 @@
from test.test_support import TestFailed from test.test_support import TestFailed, TESTFN
import os, tempfile import os
import wave import wave
def check(t, msg=None): def check(t, msg=None):
@ -11,9 +11,7 @@ sampwidth = 2
framerate = 8000 framerate = 8000
nframes = 100 nframes = 100
testfile = tempfile.mktemp() f = wave.open(TESTFN, 'wb')
f = wave.open(testfile, 'wb')
f.setnchannels(nchannels) f.setnchannels(nchannels)
f.setsampwidth(sampwidth) f.setsampwidth(sampwidth)
f.setframerate(framerate) f.setframerate(framerate)
@ -22,7 +20,7 @@ output = '\0' * nframes * nchannels * sampwidth
f.writeframes(output) f.writeframes(output)
f.close() f.close()
f = wave.open(testfile, 'rb') f = wave.open(TESTFN, 'rb')
check(nchannels == f.getnchannels(), "nchannels") check(nchannels == f.getnchannels(), "nchannels")
check(sampwidth == f.getsampwidth(), "sampwidth") check(sampwidth == f.getsampwidth(), "sampwidth")
check(framerate == f.getframerate(), "framerate") check(framerate == f.getframerate(), "framerate")
@ -31,4 +29,4 @@ input = f.readframes(nframes)
check(input == output, "data") check(input == output, "data")
f.close() f.close()
os.remove(testfile) os.remove(TESTFN)

View file

@ -11,7 +11,7 @@ import anydbm
import tempfile import tempfile
import glob import glob
_fname = tempfile.mktemp() _fname = test.test_support.TESTFN
def _delete_files(): def _delete_files():
# we don't know the precise name the underlying database uses # we don't know the precise name the underlying database uses

View file

@ -75,7 +75,8 @@ def toaiff(filename):
def _toaiff(filename, temps): def _toaiff(filename, temps):
if filename[-2:] == '.Z': if filename[-2:] == '.Z':
fname = tempfile.mktemp() (fd, fname) = tempfile.mkstemp()
os.close(fd)
temps.append(fname) temps.append(fname)
sts = uncompress.copy(filename, fname) sts = uncompress.copy(filename, fname)
if sts: if sts:
@ -98,7 +99,8 @@ def _toaiff(filename, temps):
if ftype is None or not ftype in table: if ftype is None or not ftype in table:
raise error, \ raise error, \
filename + ': unsupported audio file type ' + `ftype` filename + ': unsupported audio file type ' + `ftype`
temp = tempfile.mktemp() (fd, temp) = tempfile.mktemp()
os.close(fd)
temps.append(temp) temps.append(temp)
sts = table[ftype].copy(fname, temp) sts = table[ftype].copy(fname, temp)
if sts: if sts:

View file

@ -212,19 +212,21 @@ class URLopener:
pass pass
fp = self.open(url, data) fp = self.open(url, data)
headers = fp.info() headers = fp.info()
if not filename: if filename:
tfp = open(filename, 'wb')
else:
import tempfile import tempfile
garbage, path = splittype(url) garbage, path = splittype(url)
garbage, path = splithost(path or "") garbage, path = splithost(path or "")
path, garbage = splitquery(path or "") path, garbage = splitquery(path or "")
path, garbage = splitattr(path or "") path, garbage = splitattr(path or "")
suffix = os.path.splitext(path)[1] suffix = os.path.splitext(path)[1]
filename = tempfile.mktemp(suffix) (fd, filename) = tempfile.mkstemp(suffix)
self.__tempfiles.append(filename) self.__tempfiles.append(filename)
tfp = os.open(fd, 'wb')
result = filename, headers result = filename, headers
if self.tempcache is not None: if self.tempcache is not None:
self.tempcache[url] = result self.tempcache[url] = result
tfp = open(filename, 'wb')
bs = 1024*8 bs = 1024*8
size = -1 size = -1
blocknum = 1 blocknum = 1

View file

@ -15,15 +15,13 @@ import test
import tempfile import tempfile
def copy_test_suite(): def copy_test_suite():
dest = tempfile.mktemp() dest = tempfile.mkdtemp()
os.mkdir(dest)
os.system("cp -r %s/* %s" % (test.__path__[0], dest)) os.system("cp -r %s/* %s" % (test.__path__[0], dest))
print "Creating copy of test suite in", dest print "Creating copy of test suite in", dest
return dest return dest
def copy_library(): def copy_library():
dest = tempfile.mktemp() dest = tempfile.mkdtemp()
os.mkdir(dest)
libdir = os.path.split(test.__path__[0])[0] libdir = os.path.split(test.__path__[0])[0]
print "Found standard library in", libdir print "Found standard library in", libdir
print "Creating copy of standard library in", dest print "Creating copy of standard library in", dest

View file

@ -807,19 +807,19 @@ class FaqWizard:
f.close() f.close()
import tempfile import tempfile
tfn = tempfile.mktemp() tf = tempfile.NamedTemporaryFile()
f = open(tfn, 'w') emit(LOGHEADER, self.ui, os.environ, date=date, _file=tfn)
emit(LOGHEADER, self.ui, os.environ, date=date, _file=f) tf.flush()
f.close() tf.seek(0)
command = interpolate(SH_CHECKIN, file=file, tfn=tfn) command = interpolate(SH_CHECKIN, file=file, tfn=tf.name)
log("\n\n" + command) log("\n\n" + command)
p = os.popen(command) p = os.popen(command)
output = p.read() output = p.read()
sts = p.close() sts = p.close()
log("output: " + output) log("output: " + output)
log("done: " + str(sts)) log("done: " + str(sts))
log("TempFile:\n" + open(tfn).read() + "end") log("TempFile:\n" + tf.read() + "end")
if not sts: if not sts:
self.prologue(T_COMMITTED) self.prologue(T_COMMITTED)

View file

@ -280,9 +280,11 @@ class IOBinding:
if self.get_saved(): if self.get_saved():
filename = self.filename filename = self.filename
else: else:
filename = tempfilename = tempfile.mktemp() (tfd, tfn) = tempfile.mkstemp()
os.close(tfd)
filename = tfn
if not self.writefile(filename): if not self.writefile(filename):
os.unlink(tempfilename) os.unlink(tfn)
return "break" return "break"
edconf = idleconf.getsection('EditorWindow') edconf = idleconf.getsection('EditorWindow')
command = edconf.get('print-command') command = edconf.get('print-command')