object.
"""
- def __init__(self, fileobj, offset, size, blockinfo=None):
+ def __init__(self, fileobj, offset, size, name, blockinfo=None):
self.fileobj = fileobj
self.offset = offset
self.size = size
self.position = 0
- self.name = getattr(fileobj, "name", None)
+ self.name = name
self.closed = False
if blockinfo is None:
def __init__(self, tarfile, tarinfo):
fileobj = _FileInFile(tarfile.fileobj, tarinfo.offset_data,
- tarinfo.size, tarinfo.sparse)
+ tarinfo.size, tarinfo.name, tarinfo.sparse)
super().__init__(fileobj)
#class ExFileObject
with tarfile.open(support.findfile('recursion.tar')) as tar:
pass
+ def test_extractfile_name(self):
+ # gh-74468: TarFile.name must name a file, not a parent archive.
+ file = self.tar.getmember('ustar/regtype')
+ with self.tar.extractfile(file) as fobj:
+ self.assertEqual(fobj.name, 'ustar/regtype')
+
+
class MiscReadTestBase(CommonReadTest):
def requires_name_attribute(self):
pass