summaryrefslogtreecommitdiffstats
path: root/Lib/tarfile.py
diff options
context:
space:
mode:
authorLars Gustäbel <lars@gustaebel.de>2012-05-14 11:18:16 (GMT)
committerLars Gustäbel <lars@gustaebel.de>2012-05-14 11:18:16 (GMT)
commitb062a2fa177021195b7595f663b7a9b3bce6a8c8 (patch)
tree6333c260c31882acca5906515f4b454525b9396c /Lib/tarfile.py
parentc31dd2b56487af969b2e117093cc1465b862d3c6 (diff)
downloadcpython-b062a2fa177021195b7595f663b7a9b3bce6a8c8.zip
cpython-b062a2fa177021195b7595f663b7a9b3bce6a8c8.tar.gz
cpython-b062a2fa177021195b7595f663b7a9b3bce6a8c8.tar.bz2
Issue #13815: Resurrect the ExFileObject class.
After a discussion in the tracker, the decision was made to keep the ExFileObject class after all as a subclass of io.BufferedReader instead of removing it completely.
Diffstat (limited to 'Lib/tarfile.py')
-rw-r--r--Lib/tarfile.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/Lib/tarfile.py b/Lib/tarfile.py
index e273787..8dd4c0f 100644
--- a/Lib/tarfile.py
+++ b/Lib/tarfile.py
@@ -758,6 +758,13 @@ class _FileInFile(object):
self.closed = True
#class _FileInFile
+class ExFileObject(io.BufferedReader):
+
+ def __init__(self, tarfile, tarinfo):
+ fileobj = _FileInFile(tarfile.fileobj, tarinfo.offset_data,
+ tarinfo.size, tarinfo.sparse)
+ super().__init__(fileobj)
+#class ExFileObject
#------------------
# Exported Classes
@@ -1443,8 +1450,7 @@ class TarFile(object):
tarinfo = TarInfo # The default TarInfo class to use.
- fileobject = None # The file-object for extractfile() or
- # io.BufferedReader if None.
+ fileobject = ExFileObject # The file-object for extractfile().
def __init__(self, name=None, mode="r", fileobj=None, format=None,
tarinfo=None, dereference=None, ignore_zeros=None, encoding=None,
@@ -2081,12 +2087,7 @@ class TarFile(object):
if tarinfo.isreg() or tarinfo.type not in SUPPORTED_TYPES:
# Members with unknown types are treated as regular files.
- if self.fileobject is None:
- fileobj = _FileInFile(self.fileobj, tarinfo.offset_data, tarinfo.size, tarinfo.sparse)
- return io.BufferedReader(fileobj)
- else:
- # Keep the traditional pre-3.3 API intact.
- return self.fileobject(self, tarinfo)
+ return self.fileobject(self, tarinfo)
elif tarinfo.islnk() or tarinfo.issym():
if isinstance(self.fileobj, _Stream):