Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b062a2f

Browse files
committed
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.
1 parent c31dd2b commit b062a2f

2 files changed

Lines changed: 11 additions & 10 deletions

File tree

Lib/tarfile.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,13 @@ def close(self):
758758
self.closed = True
759759
#class _FileInFile
760760

761+
class ExFileObject(io.BufferedReader):
762+
763+
def __init__(self, tarfile, tarinfo):
764+
fileobj = _FileInFile(tarfile.fileobj, tarinfo.offset_data,
765+
tarinfo.size, tarinfo.sparse)
766+
super().__init__(fileobj)
767+
#class ExFileObject
761768

762769
#------------------
763770
# Exported Classes
@@ -1443,8 +1450,7 @@ class TarFile(object):
14431450

14441451
tarinfo = TarInfo # The default TarInfo class to use.
14451452

1446-
fileobject = None # The file-object for extractfile() or
1447-
# io.BufferedReader if None.
1453+
fileobject = ExFileObject # The file-object for extractfile().
14481454

14491455
def __init__(self, name=None, mode="r", fileobj=None, format=None,
14501456
tarinfo=None, dereference=None, ignore_zeros=None, encoding=None,
@@ -2081,12 +2087,7 @@ def extractfile(self, member):
20812087

20822088
if tarinfo.isreg() or tarinfo.type not in SUPPORTED_TYPES:
20832089
# Members with unknown types are treated as regular files.
2084-
if self.fileobject is None:
2085-
fileobj = _FileInFile(self.fileobj, tarinfo.offset_data, tarinfo.size, tarinfo.sparse)
2086-
return io.BufferedReader(fileobj)
2087-
else:
2088-
# Keep the traditional pre-3.3 API intact.
2089-
return self.fileobject(self, tarinfo)
2090+
return self.fileobject(self, tarinfo)
20902091

20912092
elif tarinfo.islnk() or tarinfo.issym():
20922093
if isinstance(self.fileobj, _Stream):

Misc/NEWS

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Core and Builtins
2626
Library
2727
-------
2828

29+
- Issue #13815: TarFile.extractfile() now returns io.BufferedReader objects.
30+
2931
- Issue #14532: Add a secure_compare() helper to the hmac module, to mitigate
3032
timing attacks. Patch by Jon Oberheide.
3133

@@ -181,8 +183,6 @@ Core and Builtins
181183
Library
182184
-------
183185

184-
- Issue #13815: TarFile.extractfile() now returns io.BufferedReader objects.
185-
186186
- Issue #14768: os.path.expanduser('~/a') doesn't works correctly when HOME is '/'.
187187

188188
- Issue #14371: Support bzip2 in zipfile module. Patch by Serhiy Storchaka.

0 commit comments

Comments
 (0)