Skip to content

Commit 8eb63c9

Browse files
committed
Revert "gh-84481: Make ZipFile.data_offset more robust (#132178)"
This reverts commit 6cd1d6c.
1 parent 65d2c51 commit 8eb63c9

File tree

2 files changed

+2
-9
lines changed

2 files changed

+2
-9
lines changed

Lib/test/test_zipfile/test_core.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3506,12 +3506,6 @@ def test_data_offset_write_with_prefix(self):
35063506
with zipfile.ZipFile(fp, "w") as zipfp:
35073507
self.assertEqual(zipfp.data_offset, 16)
35083508

3509-
def test_data_offset_append_with_bad_zip(self):
3510-
with io.BytesIO() as fp:
3511-
fp.write(b"this is a prefix")
3512-
with zipfile.ZipFile(fp, "a") as zipfp:
3513-
self.assertEqual(zipfp.data_offset, 16)
3514-
35153509
def test_data_offset_write_no_tell(self):
35163510
# The initializer in ZipFile checks if tell raises AttributeError or
35173511
# OSError when creating a file in write mode when deducing the offset
@@ -3521,7 +3515,7 @@ def tell(self):
35213515
raise OSError("Unimplemented!")
35223516
with NoTellBytesIO() as fp:
35233517
with zipfile.ZipFile(fp, "w") as zipfp:
3524-
self.assertIsNone(zipfp.data_offset)
3518+
self.assertIs(zipfp.data_offset, None)
35253519

35263520

35273521
class EncodedMetadataTests(unittest.TestCase):

Lib/zipfile/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,7 +1452,6 @@ def __init__(self, file, mode="r", compression=ZIP_STORED, allowZip64=True,
14521452
self._lock = threading.RLock()
14531453
self._seekable = True
14541454
self._writing = False
1455-
self._data_offset = None
14561455

14571456
try:
14581457
if mode == 'r':
@@ -1468,6 +1467,7 @@ def __init__(self, file, mode="r", compression=ZIP_STORED, allowZip64=True,
14681467
self.fp = _Tellable(self.fp)
14691468
self.start_dir = 0
14701469
self._seekable = False
1470+
self._data_offset = None
14711471
else:
14721472
# Some file-like objects can provide tell() but not seek()
14731473
try:
@@ -1488,7 +1488,6 @@ def __init__(self, file, mode="r", compression=ZIP_STORED, allowZip64=True,
14881488
# even if no files are added to the archive
14891489
self._didModify = True
14901490
self.start_dir = self.fp.tell()
1491-
self._data_offset = self.start_dir
14921491
else:
14931492
raise ValueError("Mode must be 'r', 'w', 'x', or 'a'")
14941493
except:

0 commit comments

Comments
 (0)