[Python-checkins] python/dist/src/Lib cgitb.py,1.5,1.6 mimetools.py,1.26,1.27 pipes.py,1.11,1.12 pydoc.py,1.66,1.67 toaiff.py,1.12,1.13 urllib.py,1.148,1.149

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
Fri, 09 Aug 2002 09:38:06 -0700


Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv22967/Lib

Modified Files:
	cgitb.py mimetools.py pipes.py pydoc.py toaiff.py urllib.py 
Log Message:
Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Weinberg).  This changes all uses of deprecated tempfile functions to
the recommended ones.


Index: cgitb.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/cgitb.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** cgitb.py	26 Jun 2002 07:10:56 -0000	1.5
--- cgitb.py	9 Aug 2002 16:37:33 -0000	1.6
***************
*** 194,201 ****
          if self.logdir is not None:
              import os, tempfile
!             name = tempfile.mktemp(['.html', '.txt'][text])
!             path = os.path.join(self.logdir, os.path.basename(name))
              try:
!                 file = open(path, 'w')
                  file.write(doc)
                  file.close()
--- 194,201 ----
          if self.logdir is not None:
              import os, tempfile
!             (fd, name) = tempfile.mkstemp(suffix=['.html', '.txt'][text],
!                                           dir=self.logdir)
              try:
!                 file = os.fdopen(fd, 'w')
                  file.write(doc)
                  file.close()

Index: mimetools.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/mimetools.py,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -d -r1.26 -r1.27
*** mimetools.py	1 Jun 2002 14:18:46 -0000	1.26
--- mimetools.py	9 Aug 2002 16:37:33 -0000	1.27
***************
*** 203,208 ****
  
  def pipethrough(input, command, output):
!     tempname = tempfile.mktemp()
!     temp = open(tempname, 'w')
      copyliteral(input, temp)
      temp.close()
--- 203,208 ----
  
  def pipethrough(input, command, output):
!     (fd, tempname) = tempfile.mkstemp()
!     temp = os.fdopen(fd, 'w')
      copyliteral(input, temp)
      temp.close()

Index: pipes.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/pipes.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** pipes.py	2 Aug 2001 07:15:29 -0000	1.11
--- pipes.py	9 Aug 2002 16:37:33 -0000	1.12
***************
*** 226,230 ****
          rkind = list[i][2]
          if lkind[1] == 'f' or rkind[0] == 'f':
!             temp = tempfile.mktemp()
              garbage.append(temp)
              list[i-1][-1] = list[i][0] = temp
--- 226,231 ----
          rkind = list[i][2]
          if lkind[1] == 'f' or rkind[0] == 'f':
!             (fd, temp) = tempfile.mkstemp()
!             os.close(fd)
              garbage.append(temp)
              list[i-1][-1] = list[i][0] = temp

Index: pydoc.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/pydoc.py,v
retrieving revision 1.66
retrieving revision 1.67
diff -C2 -d -r1.66 -r1.67
*** pydoc.py	6 Aug 2002 17:29:38 -0000	1.66
--- pydoc.py	9 Aug 2002 16:37:33 -0000	1.67
***************
*** 1204,1209 ****
  
      import tempfile
!     filename = tempfile.mktemp()
!     open(filename, 'w').close()
      try:
          if hasattr(os, 'system') and os.system('more %s' % filename) == 0:
--- 1204,1209 ----
  
      import tempfile
!     (fd, filename) = tempfile.mkstemp()
!     os.close(fd)
      try:
          if hasattr(os, 'system') and os.system('more %s' % filename) == 0:
***************
*** 1230,1235 ****
      """Page through text by invoking a program on a temporary file."""
      import tempfile
!     filename = tempfile.mktemp()
!     file = open(filename, 'w')
      file.write(text)
      file.close()
--- 1230,1235 ----
      """Page through text by invoking a program on a temporary file."""
      import tempfile
!     (fd, filename) = tempfile.mkstemp()
!     file = os.fdopen(fd, 'w')
      file.write(text)
      file.close()

Index: toaiff.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/toaiff.py,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** toaiff.py	1 Jun 2002 14:18:47 -0000	1.12
--- toaiff.py	9 Aug 2002 16:37:33 -0000	1.13
***************
*** 76,80 ****
  def _toaiff(filename, temps):
      if filename[-2:] == '.Z':
!         fname = tempfile.mktemp()
          temps.append(fname)
          sts = uncompress.copy(filename, fname)
--- 76,81 ----
  def _toaiff(filename, temps):
      if filename[-2:] == '.Z':
!         (fd, fname) = tempfile.mkstemp()
!         os.close(fd)
          temps.append(fname)
          sts = uncompress.copy(filename, fname)
***************
*** 99,103 ****
          raise error, \
                  filename + ': unsupported audio file type ' + `ftype`
!     temp = tempfile.mktemp()
      temps.append(temp)
      sts = table[ftype].copy(fname, temp)
--- 100,105 ----
          raise error, \
                  filename + ': unsupported audio file type ' + `ftype`
!     (fd, temp) = tempfile.mktemp()
!     os.close(fd)
      temps.append(temp)
      sts = table[ftype].copy(fname, temp)

Index: urllib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/urllib.py,v
retrieving revision 1.148
retrieving revision 1.149
diff -C2 -d -r1.148 -r1.149
*** urllib.py	11 Jun 2002 13:38:51 -0000	1.148
--- urllib.py	9 Aug 2002 16:37:33 -0000	1.149
***************
*** 213,217 ****
          fp = self.open(url, data)
          headers = fp.info()
!         if not filename:
              import tempfile
              garbage, path = splittype(url)
--- 213,219 ----
          fp = self.open(url, data)
          headers = fp.info()
!         if filename:
!             tfp = open(filename, 'wb')
!         else:
              import tempfile
              garbage, path = splittype(url)
***************
*** 220,229 ****
              path, garbage = splitattr(path or "")
              suffix = os.path.splitext(path)[1]
!             filename = tempfile.mktemp(suffix)
              self.__tempfiles.append(filename)
          result = filename, headers
          if self.tempcache is not None:
              self.tempcache[url] = result
-         tfp = open(filename, 'wb')
          bs = 1024*8
          size = -1
--- 222,231 ----
              path, garbage = splitattr(path or "")
              suffix = os.path.splitext(path)[1]
!             (fd, filename) = tempfile.mkstemp(suffix)
              self.__tempfiles.append(filename)
+             tfp = os.open(fd, 'wb')
          result = filename, headers
          if self.tempcache is not None:
              self.tempcache[url] = result
          bs = 1024*8
          size = -1