Commit graph

65 commits

Author SHA1 Message Date
Danny Lin
5f093e5175 Sync with danny0838/zipremove@1691ca25bf 2025-06-20 15:34:58 +08:00
Danny Lin
3b2f2328b6 Remove unneeded catch type
- NotImplementedError is a subclass of RuntimeError.
2025-06-14 13:48:21 +08:00
Danny Lin
797a62cd8f Fix and optimize repack 2025-06-01 17:50:28 +08:00
Danny Lin
c470c33389 Fix _scan_data_descriptor_no_sig_by_decompression when library not available 2025-06-01 15:48:01 +08:00
Danny Lin
1d5ec61337 Fix _scan_data_descriptor_no_sig_by_decompression 2025-06-01 15:11:33 +08:00
Danny Lin
b5d7ae3a6a Rename _trace_compressed_block_end 2025-06-01 14:59:29 +08:00
Danny Lin
92d3a9c418 Fix and optimize _scan_data_descriptor_no_sig 2025-06-01 14:12:03 +08:00
Danny Lin
8067b0c489 Fix _scan_data_descriptor 2025-06-01 14:11:57 +08:00
Danny Lin
fef92c45a3 Fix and optimize _iter_scan_signature 2025-06-01 14:11:51 +08:00
Danny Lin
ea3259fba7 Optimize code 2025-06-01 14:11:43 +08:00
Danny Lin
c80d21bf99 Strip only entries immediately following a referenced entry
- The previous implementation might cause [archive decryption header] and/or [archive extra data record] preceeding [central directory] be stripped.
2025-05-30 20:57:36 +08:00
Danny Lin
f8fade17a0 Introduce _scan_data_descriptor_no_sig_by_decompression 2025-05-30 20:56:31 +08:00
Danny Lin
31c4c936c6 Rework _validate_local_file_entry_sequence to allow passing no checked_offsets 2025-05-30 13:59:53 +08:00
Danny Lin
3d0240c1a3 Rework _validate_local_file_entry_sequence to return size or None 2025-05-30 13:59:53 +08:00
Danny Lin
a05353c476 Improve debug for _ZipRepacker.repack() 2025-05-30 13:59:52 +08:00
Danny Lin
c62a4556ff Optimize code and revise comment
- According to ZIP spec, both uncompressed and compressed size should be 0xffffffff when zip64 is used.
2025-05-29 10:46:11 +08:00
Danny Lin
81a419aaf7 Adjust parameter order 2025-05-29 10:46:11 +08:00
Danny Lin
fbf75888fc Rename methods and parameters 2025-05-28 11:46:48 +08:00
Danny Lin
9e94209e94 Revise docstring 2025-05-27 08:27:17 +08:00
Danny Lin
e76f9a1bc1 Fix bytes between entries be removed when removed is passed 2025-05-27 00:20:40 +08:00
Danny Lin
926338cbc1 Support repack(removed) 2025-05-26 23:46:17 +08:00
Danny Lin
edee2033c4 Rework writing protection
- Set `_writing` to prevent `open('w').write()` during repacking.
- Move the protection logic to `ZipFile.repack()`.
2025-05-25 22:09:29 +08:00
Danny Lin
ae01b8cd69 Raise on overlapping file blocks 2025-05-25 21:09:12 +08:00
Danny Lin
a788a001a4 Use zinfo rather than info 2025-05-25 21:08:49 +08:00
Danny Lin
0cb8682dfa Remove obsolete NameToInfo updating 2025-05-25 21:07:52 +08:00
Danny Lin
0d971d81b5 Add strict_descriptor option 2025-05-25 10:19:06 +08:00
Danny Lin
51c9254cfb Refactor _validate_local_file_entry 2025-05-25 10:09:49 +08:00
Danny Lin
1b7d75a4ea Introduce _move_entry_data and rework chunk_size passing 2025-05-25 10:09:41 +08:00
Danny Lin
c3c834505f Introduce _debug and refactor 2025-05-25 10:09:33 +08:00
Danny Lin
bdc58c7111 Introduce _validate_local_file_entry and refactor 2025-05-25 10:09:26 +08:00
Danny Lin
236cd06084 Optimize _calc_initial_entry_offset by introducing cache 2025-05-25 10:09:18 +08:00
Danny Lin
a9e85c654c Introduce _calc_initial_entry_offset and refactor 2025-05-25 10:09:10 +08:00
Danny Lin
6aed859ade Add remove() and repack() to ZipFile 2025-05-24 18:54:06 +08:00
Tim Hatch
1298511b41
gh-72680: Fix false positives when using zipfile.is_zipfile() (GH-134250)
bpo-28494: Improve zipfile.is_zipfile reliability

The zipfile.is_zipfile function would only search for the EndOfZipfile
section header. This failed to correctly identify non-zipfiles that
contained this header. Now the zipfile.is_zipfile function verifies
the first central directory entry.

Changes:
* Extended zipfile.is_zipfile to verify zipfile catalog
* Added tests to validate failure of binary non-zipfiles
* Reuse 'concat' handling for is_zipfile

Co-authored-by: John Jolly <john.jolly@gmail.com>
2025-05-20 18:32:41 -07:00
Carey Metcalfe
35f47d0589
gh-132983: Fix small issues with zstd support in zipfile (#133723)
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Co-authored-by: Emma Smith <emma@emmatyping.dev>
2025-05-13 16:43:09 +01:00
Emma Smith
c273f59fb3
gh-132983: Add the compression.zstd pacakge and tests (#133365)
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
Co-authored-by: Rogdham <contact@rogdham.net>
2025-05-06 01:38:08 +01:00
Hugo van Kemenade
4ac916ae33
gh-130645: Add color to stdlib argparse CLIs (gh-133380) 2025-05-05 19:46:46 +02:00
Serhiy Storchaka
0f04f2456a
gh-117779: Fix reading duplicated entries in zipfile by name (GH-129254) 2025-04-08 13:56:42 +03:00
Emma Smith
6cd1d6c6b1
gh-84481: Make ZipFile.data_offset more robust (#132178) 2025-04-08 10:43:14 +03:00
Emma Smith
0788948dcb
gh-84481: Add ZipFile.data_offset attribute (#132165)
* Add ZipFile.data_offset attribute

This attribute provides the offset to zip data from the start of the file, when available.

* Add blurb-it

* Try fixing class ref in NEWS
2025-04-06 13:51:42 -07:00
Bénédikt Tran
a95dca7b98
gh-118761: Improve import time for pstats and zipfile (#128981)
Importing `pstats` or `zipfile` is now roughly 20% faster.

This is achieved by removing type annotations depending on `typing`.
2025-01-23 14:49:36 +00:00
Wulian
5d57959d7d
gh-91279: ZipFile.writestr now respect SOURCE_DATE_EPOCH (#124435) 2025-01-20 13:12:29 -05:00
5ec1cff
dda02eb7be
GH-128131: Completely support random read access of uncompressed unencrypted files in ZipFile (#128143)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2025-01-20 13:04:43 -05:00
Bénédikt Tran
7e819ce0f3
gh-123424: add ZipInfo._for_archive to set suitable default properties (#123429)
---------

Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
2024-12-29 18:30:53 +00:00
Dima Ryazanov
7ed6c5c696
gh-127847: Fix position in the special-cased zipfile seek (#127856)
---------

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
2024-12-24 15:56:42 +00:00
Bénédikt Tran
e0ef08f5b4
gh-122356: restore the position of a file-like object after zipfile.is_zipfile (#122397) 2024-11-24 11:36:15 -05:00
Cody Maloney
556dc9b8a7
gh-113977, gh-120754: Remove unbounded reads from zipfile (GH-122101)
GH-113977, GH-120754: Remove unbounded reads from zipfile

Read without a size may read an unbounded amount of data + allocate
unbounded size buffers. Move to capped size reads to prevent potential
issues.

Co-authored-by: Daniel Hillier <daniel.hillier@gmail.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
2024-11-02 22:28:51 -07:00
Geoffrey Thomas
ef172521a9
Remove almost all unpaired backticks in docstrings (#119231)
As reported in #117847 and #115366, an unpaired backtick in a docstring
tends to confuse e.g. Sphinx running on subclasses of standard library
objects, and the typographic style of using a backtick as an opening
quote is no longer in favor. Convert almost all uses of the form

    The variable `foo' should do xyz

to

    The variable 'foo' should do xyz

and also fix up miscellaneous other unpaired backticks (extraneous /
missing characters).

No functional change is intended here other than in human-readable
docstrings.
2024-05-22 12:35:18 -04:00
Serhiy Storchaka
51ef89cd9a
gh-115961: Add name and mode attributes for compressed file-like objects (GH-116036)
* Add name and mode attributes for compressed and archived file-like objects
  in modules bz2, lzma, tarfile and zipfile.
* Change the value of the mode attribute of GzipFile from integer (1 or 2)
  to string ('rb' or 'wb').
* Change the value of the mode attribute of ZipExtFile from 'r' to 'rb'.
2024-04-21 11:46:39 +03:00
Deborah
a32d693948
gh-102190: Add additional zipfile pwd= arg docstrings (gh-102195)
This just documents the parameter that already exists.

---------

Co-authored-by: Gregory P. Smith <greg@krypto.org>
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
2024-03-31 20:11:48 +00:00