|
65 | 65 | # from tarfile import * |
66 | 66 | __all__ = ["TarFile", "TarInfo", "is_tarfile", "TarError"] |
67 | 67 |
|
| 68 | +from __builtin__ import open as _open # Since 'open' is TarFile.open |
| 69 | + |
68 | 70 | #--------------------------------------------------------- |
69 | 71 | # tar constants |
70 | 72 | #--------------------------------------------------------- |
@@ -934,7 +936,7 @@ def __init__(self, name=None, mode="r", fileobj=None): |
934 | 936 | self.mode = {"r": "rb", "a": "r+b", "w": "wb"}[mode] |
935 | 937 |
|
936 | 938 | if not fileobj: |
937 | | - fileobj = open(self.name, self.mode) |
| 939 | + fileobj = _open(self.name, self.mode) |
938 | 940 | self._extfileobj = False |
939 | 941 | else: |
940 | 942 | if self.name is None and hasattr(fileobj, "name"): |
@@ -1083,7 +1085,7 @@ def gzopen(cls, name, mode="r", fileobj=None, compresslevel=9): |
1083 | 1085 | tarname = pre + ext |
1084 | 1086 |
|
1085 | 1087 | if fileobj is None: |
1086 | | - fileobj = open(name, mode + "b") |
| 1088 | + fileobj = _open(name, mode + "b") |
1087 | 1089 |
|
1088 | 1090 | if mode != "r": |
1089 | 1091 | name = tarname |
@@ -1355,7 +1357,7 @@ def add(self, name, arcname=None, recursive=True): |
1355 | 1357 |
|
1356 | 1358 | # Append the tar header and data to the archive. |
1357 | 1359 | if tarinfo.isreg(): |
1358 | | - f = open(name, "rb") |
| 1360 | + f = _open(name, "rb") |
1359 | 1361 | self.addfile(tarinfo, f) |
1360 | 1362 | f.close() |
1361 | 1363 |
|
@@ -1617,7 +1619,7 @@ def makefile(self, tarinfo, targetpath): |
1617 | 1619 | """Make a file called targetpath. |
1618 | 1620 | """ |
1619 | 1621 | source = self.extractfile(tarinfo) |
1620 | | - target = open(targetpath, "wb") |
| 1622 | + target = _open(targetpath, "wb") |
1621 | 1623 | copyfileobj(source, target) |
1622 | 1624 | source.close() |
1623 | 1625 | target.close() |
|
0 commit comments