Skip to content

Commit 217f063

Browse files
committed
Fix fallout from Anna's file -> open changes.
1 parent 76ea868 commit 217f063

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

Lib/tarfile.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@
6565
# from tarfile import *
6666
__all__ = ["TarFile", "TarInfo", "is_tarfile", "TarError"]
6767

68+
from __builtin__ import open as _open # Since 'open' is TarFile.open
69+
6870
#---------------------------------------------------------
6971
# tar constants
7072
#---------------------------------------------------------
@@ -934,7 +936,7 @@ def __init__(self, name=None, mode="r", fileobj=None):
934936
self.mode = {"r": "rb", "a": "r+b", "w": "wb"}[mode]
935937

936938
if not fileobj:
937-
fileobj = open(self.name, self.mode)
939+
fileobj = _open(self.name, self.mode)
938940
self._extfileobj = False
939941
else:
940942
if self.name is None and hasattr(fileobj, "name"):
@@ -1083,7 +1085,7 @@ def gzopen(cls, name, mode="r", fileobj=None, compresslevel=9):
10831085
tarname = pre + ext
10841086

10851087
if fileobj is None:
1086-
fileobj = open(name, mode + "b")
1088+
fileobj = _open(name, mode + "b")
10871089

10881090
if mode != "r":
10891091
name = tarname
@@ -1355,7 +1357,7 @@ def add(self, name, arcname=None, recursive=True):
13551357

13561358
# Append the tar header and data to the archive.
13571359
if tarinfo.isreg():
1358-
f = open(name, "rb")
1360+
f = _open(name, "rb")
13591361
self.addfile(tarinfo, f)
13601362
f.close()
13611363

@@ -1617,7 +1619,7 @@ def makefile(self, tarinfo, targetpath):
16171619
"""Make a file called targetpath.
16181620
"""
16191621
source = self.extractfile(tarinfo)
1620-
target = open(targetpath, "wb")
1622+
target = _open(targetpath, "wb")
16211623
copyfileobj(source, target)
16221624
source.close()
16231625
target.close()

0 commit comments

Comments
 (0)