[Python-checkins] r55592 - in python/trunk/Lib: tarfile.py test/test_zipfile.py
brett.cannon
python-checkins at python.org
Fri May 25 22:17:18 CEST 2007
Author: brett.cannon
Date: Fri May 25 22:17:15 2007
New Revision: 55592
Modified:
python/trunk/Lib/tarfile.py
python/trunk/Lib/test/test_zipfile.py
Log:
Remove direct call's to file's constructor and replace them with calls to
open() as ths is considered best practice.
Modified: python/trunk/Lib/tarfile.py
==============================================================================
--- python/trunk/Lib/tarfile.py (original)
+++ python/trunk/Lib/tarfile.py Fri May 25 22:17:15 2007
@@ -1490,7 +1490,7 @@
# 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 @@
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 @@
# 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 @@
"""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 @@
except TarError:
return False
+bltn_open = open
open = TarFile.open
Modified: python/trunk/Lib/test/test_zipfile.py
==============================================================================
--- python/trunk/Lib/test/test_zipfile.py (original)
+++ python/trunk/Lib/test/test_zipfile.py Fri May 25 22:17:15 2007
@@ -712,7 +712,7 @@
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
More information about the Python-checkins
mailing list