Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Weinberg).  This changes all uses of deprecated tempfile functions to
the recommended ones.
diff --git a/Tools/compiler/regrtest.py b/Tools/compiler/regrtest.py
index aae0ec2..def07c2 100644
--- a/Tools/compiler/regrtest.py
+++ b/Tools/compiler/regrtest.py
@@ -15,15 +15,13 @@
 import tempfile
 
 def copy_test_suite():
-    dest = tempfile.mktemp()
-    os.mkdir(dest)
+    dest = tempfile.mkdtemp()
     os.system("cp -r %s/* %s" % (test.__path__[0], dest))
     print "Creating copy of test suite in", dest
     return dest
 
 def copy_library():
-    dest = tempfile.mktemp()
-    os.mkdir(dest)
+    dest = tempfile.mkdtemp()
     libdir = os.path.split(test.__path__[0])[0]
     print "Found standard library in", libdir
     print "Creating copy of standard library in", dest
diff --git a/Tools/faqwiz/faqwiz.py b/Tools/faqwiz/faqwiz.py
index 638da17..2e2a8b5 100644
--- a/Tools/faqwiz/faqwiz.py
+++ b/Tools/faqwiz/faqwiz.py
@@ -807,19 +807,19 @@
         f.close()
 
         import tempfile
-        tfn = tempfile.mktemp()
-        f = open(tfn, 'w')
-        emit(LOGHEADER, self.ui, os.environ, date=date, _file=f)
-        f.close()
+        tf = tempfile.NamedTemporaryFile()
+        emit(LOGHEADER, self.ui, os.environ, date=date, _file=tfn)
+        tf.flush()
+        tf.seek(0)
 
-        command = interpolate(SH_CHECKIN, file=file, tfn=tfn)
+        command = interpolate(SH_CHECKIN, file=file, tfn=tf.name)
         log("\n\n" + command)
         p = os.popen(command)
         output = p.read()
         sts = p.close()
         log("output: " + output)
         log("done: " + str(sts))
-        log("TempFile:\n" + open(tfn).read() + "end")
+        log("TempFile:\n" + tf.read() + "end")
         
         if not sts:
             self.prologue(T_COMMITTED)
diff --git a/Tools/idle/IOBinding.py b/Tools/idle/IOBinding.py
index 0ea4524..d80e53c 100644
--- a/Tools/idle/IOBinding.py
+++ b/Tools/idle/IOBinding.py
@@ -280,9 +280,11 @@
         if self.get_saved():
             filename = self.filename
         else:
-            filename = tempfilename = tempfile.mktemp()
+            (tfd, tfn) = tempfile.mkstemp()
+            os.close(tfd)
+            filename = tfn
             if not self.writefile(filename):
-                os.unlink(tempfilename)
+                os.unlink(tfn)
                 return "break"
         edconf = idleconf.getsection('EditorWindow')
         command = edconf.get('print-command')