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.
This commit is contained in:
parent
c31dd2b564
commit
b062a2fa17
|
@ -758,6 +758,13 @@ class _FileInFile(object):
|
||||||
self.closed = True
|
self.closed = True
|
||||||
#class _FileInFile
|
#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
|
# Exported Classes
|
||||||
|
@ -1443,8 +1450,7 @@ class TarFile(object):
|
||||||
|
|
||||||
tarinfo = TarInfo # The default TarInfo class to use.
|
tarinfo = TarInfo # The default TarInfo class to use.
|
||||||
|
|
||||||
fileobject = None # The file-object for extractfile() or
|
fileobject = ExFileObject # The file-object for extractfile().
|
||||||
# io.BufferedReader if None.
|
|
||||||
|
|
||||||
def __init__(self, name=None, mode="r", fileobj=None, format=None,
|
def __init__(self, name=None, mode="r", fileobj=None, format=None,
|
||||||
tarinfo=None, dereference=None, ignore_zeros=None, encoding=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:
|
if tarinfo.isreg() or tarinfo.type not in SUPPORTED_TYPES:
|
||||||
# Members with unknown types are treated as regular files.
|
# Members with unknown types are treated as regular files.
|
||||||
if self.fileobject is None:
|
return self.fileobject(self, tarinfo)
|
||||||
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)
|
|
||||||
|
|
||||||
elif tarinfo.islnk() or tarinfo.issym():
|
elif tarinfo.islnk() or tarinfo.issym():
|
||||||
if isinstance(self.fileobj, _Stream):
|
if isinstance(self.fileobj, _Stream):
|
||||||
|
|
|
@ -26,6 +26,8 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #13815: TarFile.extractfile() now returns io.BufferedReader objects.
|
||||||
|
|
||||||
- Issue #14532: Add a secure_compare() helper to the hmac module, to mitigate
|
- Issue #14532: Add a secure_compare() helper to the hmac module, to mitigate
|
||||||
timing attacks. Patch by Jon Oberheide.
|
timing attacks. Patch by Jon Oberheide.
|
||||||
|
|
||||||
|
@ -181,8 +183,6 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
- Issue #13815: TarFile.extractfile() now returns io.BufferedReader objects.
|
|
||||||
|
|
||||||
- Issue #14768: os.path.expanduser('~/a') doesn't works correctly when HOME is '/'.
|
- Issue #14768: os.path.expanduser('~/a') doesn't works correctly when HOME is '/'.
|
||||||
|
|
||||||
- Issue #14371: Support bzip2 in zipfile module. Patch by Serhiy Storchaka.
|
- Issue #14371: Support bzip2 in zipfile module. Patch by Serhiy Storchaka.
|
||||||
|
|
Loading…
Reference in New Issue