Skip to content

Commit 4221022

Browse files
committed
Revert "gh-84481: Add ZipFile.data_offset attribute (#132165)"
This reverts commit 0788948.
1 parent 8eb63c9 commit 4221022

File tree

3 files changed

+0
-68
lines changed

3 files changed

+0
-68
lines changed

Doc/library/zipfile.rst

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -558,14 +558,6 @@ The following data attributes are also available:
558558
it should be no longer than 65535 bytes. Comments longer than this will be
559559
truncated.
560560

561-
.. attribute:: ZipFile.data_offset
562-
563-
The offset to the start of ZIP data from the beginning of the file. When the
564-
:class:`ZipFile` is opened in either mode ``'w'`` or ``'x'`` and the
565-
underlying file does not support ``tell()``, the value will be ``None``
566-
instead.
567-
568-
.. versionadded:: 3.14
569561

570562
.. _path-objects:
571563

Lib/test/test_zipfile/test_core.py

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3470,54 +3470,6 @@ def test_execute_zip64(self):
34703470
self.assertIn(b'number in executable: 5', output)
34713471

34723472

3473-
class TestDataOffsetPrependedZip(unittest.TestCase):
3474-
"""Test .data_offset on reading zip files with an executable prepended."""
3475-
3476-
def setUp(self):
3477-
self.exe_zip = findfile('exe_with_zip', subdir='archivetestdata')
3478-
self.exe_zip64 = findfile('exe_with_z64', subdir='archivetestdata')
3479-
3480-
def _test_data_offset(self, name):
3481-
with zipfile.ZipFile(name) as zipfp:
3482-
self.assertEqual(zipfp.data_offset, 713)
3483-
3484-
def test_data_offset_with_exe_prepended(self):
3485-
self._test_data_offset(self.exe_zip)
3486-
3487-
def test_data_offset_with_exe_prepended_zip64(self):
3488-
self._test_data_offset(self.exe_zip64)
3489-
3490-
class TestDataOffsetZipWrite(unittest.TestCase):
3491-
"""Test .data_offset for ZipFile opened in write mode."""
3492-
3493-
def setUp(self):
3494-
os.mkdir(TESTFNDIR)
3495-
self.addCleanup(rmtree, TESTFNDIR)
3496-
self.test_path = os.path.join(TESTFNDIR, 'testoffset.zip')
3497-
3498-
def test_data_offset_write_no_prefix(self):
3499-
with io.BytesIO() as fp:
3500-
with zipfile.ZipFile(fp, "w") as zipfp:
3501-
self.assertEqual(zipfp.data_offset, 0)
3502-
3503-
def test_data_offset_write_with_prefix(self):
3504-
with io.BytesIO() as fp:
3505-
fp.write(b"this is a prefix")
3506-
with zipfile.ZipFile(fp, "w") as zipfp:
3507-
self.assertEqual(zipfp.data_offset, 16)
3508-
3509-
def test_data_offset_write_no_tell(self):
3510-
# The initializer in ZipFile checks if tell raises AttributeError or
3511-
# OSError when creating a file in write mode when deducing the offset
3512-
# of the beginning of zip data
3513-
class NoTellBytesIO(io.BytesIO):
3514-
def tell(self):
3515-
raise OSError("Unimplemented!")
3516-
with NoTellBytesIO() as fp:
3517-
with zipfile.ZipFile(fp, "w") as zipfp:
3518-
self.assertIs(zipfp.data_offset, None)
3519-
3520-
35213473
class EncodedMetadataTests(unittest.TestCase):
35223474
file_names = ['\u4e00', '\u4e8c', '\u4e09'] # Han 'one', 'two', 'three'
35233475
file_content = [

Lib/zipfile/__init__.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,12 +1462,10 @@ def __init__(self, file, mode="r", compression=ZIP_STORED, allowZip64=True,
14621462
self._didModify = True
14631463
try:
14641464
self.start_dir = self.fp.tell()
1465-
self._data_offset = self.start_dir
14661465
except (AttributeError, OSError):
14671466
self.fp = _Tellable(self.fp)
14681467
self.start_dir = 0
14691468
self._seekable = False
1470-
self._data_offset = None
14711469
else:
14721470
# Some file-like objects can provide tell() but not seek()
14731471
try:
@@ -1534,10 +1532,6 @@ def _RealGetContents(self):
15341532
# self.start_dir: Position of start of central directory
15351533
self.start_dir = offset_cd + concat
15361534

1537-
# store the offset to the beginning of data for the
1538-
# .data_offset property
1539-
self._data_offset = concat
1540-
15411535
if self.start_dir < 0:
15421536
raise BadZipFile("Bad offset for central directory")
15431537
fp.seek(self.start_dir, 0)
@@ -1598,12 +1592,6 @@ def _RealGetContents(self):
15981592
zinfo._end_offset = end_offset
15991593
end_offset = zinfo.header_offset
16001594

1601-
@property
1602-
def data_offset(self):
1603-
"""The offset to the start of zip data in the file or None if
1604-
unavailable."""
1605-
return self._data_offset
1606-
16071595
def namelist(self):
16081596
"""Return a list of file names in the archive."""
16091597
return [data.filename for data in self.filelist]

0 commit comments

Comments
 (0)