]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Remove direct call's to file's constructor and replace them with calls to
authorBrett Cannon <bcannon@gmail.com>
Fri, 25 May 2007 20:17:15 +0000 (20:17 +0000)
committerBrett Cannon <bcannon@gmail.com>
Fri, 25 May 2007 20:17:15 +0000 (20:17 +0000)
open() as ths is considered best practice.

Lib/tarfile.py
Lib/test/test_zipfile.py

index b6dc3ee4b39549c9094fdfd7779f6986c65bad22..4f4a1d9b6b5350d4a16e5b84289fcd1a3a3a9232 100644 (file)
@@ -1490,7 +1490,7 @@ class TarFile(object):
                 # Create nonexistent files in append mode.
                 self.mode = "w"
                 self._mode = "wb"
-            fileobj = file(name, self._mode)
+            fileobj = bltn_open(name, self._mode)
             self._extfileobj = False
         else:
             if name is None and hasattr(fileobj, "name"):
@@ -1667,7 +1667,7 @@ class TarFile(object):
             raise CompressionError("gzip module is not available")
 
         if fileobj is None:
-            fileobj = file(name, mode + "b")
+            fileobj = bltn_open(name, mode + "b")
 
         try:
             t = cls.taropen(name, mode,
@@ -1928,7 +1928,7 @@ class TarFile(object):
 
         # Append the tar header and data to the archive.
         if tarinfo.isreg():
-            f = file(name, "rb")
+            f = bltn_open(name, "rb")
             self.addfile(tarinfo, f)
             f.close()
 
@@ -2139,7 +2139,7 @@ class TarFile(object):
         """Make a file called targetpath.
         """
         source = self.extractfile(tarinfo)
-        target = file(targetpath, "wb")
+        target = bltn_open(targetpath, "wb")
         copyfileobj(source, target)
         source.close()
         target.close()
@@ -2484,4 +2484,5 @@ def is_tarfile(name):
     except TarError:
         return False
 
+bltn_open = open
 open = TarFile.open
index ec519f628073a1ba92acebfd7398a6350cedaca4..49602ffdd46222dbf4f2f8e3d4b1ed9fba31e27e 100644 (file)
@@ -712,7 +712,7 @@ class UniversalNewlineTests(unittest.TestCase):
         for n, s in enumerate(self.seps):
             self.arcdata[s] = s.join(self.line_gen) + s
             self.arcfiles[s] = '%s-%d' % (TESTFN, n)
-            file(self.arcfiles[s], "wb").write(self.arcdata[s])
+            open(self.arcfiles[s], "wb").write(self.arcdata[s])
 
     def makeTestArchive(self, f, compression):
         # Create the ZIP archive