Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ZipFile.extractall fails if zipfile.Path object is created based on the ZipFile object #101566

Closed
jaraco/zipp
#90
Assignees
jaraco
Labels
3.10only security fixes3.11only security fixes3.12only security fixesstdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error
@mmohrhard

Description

@mmohrhard

Bug report

The following code works fine with Python 3.8 and 3.9 but starts failing with Python 3.10.

It seems thatzipfile.Path creates an entry in thezipfile.ZipFile object that does not exist in the underlying file and therefore makeszipfile.ZipFile.extractall fail.

import zipfileimport tempfilepath = tempfile.mktemp()f = zipfile.ZipFile(path, "w")f.writestr("data/test.txt", "test1")f.writestr("data/test2.txt", "test2")f.close()dest = tempfile.mkdtemp()p = zipfile.ZipFile(path)src_zipfile_path = zipfile.Path(p, "data")p.extractall(dest)

Your environment

Working version:

(python39) [moggi@mars cloudfluid]$ python --versionPython 3.9.16(python39) [moggi@mars cloudfluid]$ python test.py(python39) [moggi@mars cloudfluid]$

Failing versions:

3.10.9:

(python_310_2) [moggi@mars cloudfluid]$ python --versionPython 3.10.9(python_310_2) [moggi@mars cloudfluid]$ python test.pyTraceback (most recent call last):  File "/home/moggi/devel/cloudfluid/test.py", line 15, in <module>    p.extractall(dest)  File "/home/moggi/devel/envs/python_310_2/lib/python3.10/zipfile.py", line 1645, in extractall    self._extract_member(zipinfo, path, pwd)  File "/home/moggi/devel/envs/python_310_2/lib/python3.10/zipfile.py", line 1667, in _extract_member    member = self.getinfo(member)  File "/home/moggi/devel/envs/python_310_2/lib/python3.10/zipfile.py", line 1441, in getinfo    raise KeyError(KeyError: "There is no item named 'data/' in the archive"

and 3.11.0

(python311) [moggi@mars cloudfluid]$ python --versionPython 3.11.0(python311) [moggi@mars cloudfluid]$ python test.pyTraceback (most recent call last):  File "/home/moggi/devel/cloudfluid/test.py", line 15, in <module>    p.extractall(dest)  File "/home/moggi/devel/envs/python311/lib/python3.11/zipfile.py", line 1677, in extractall    self._extract_member(zipinfo, path, pwd)  File "/home/moggi/devel/envs/python311/lib/python3.11/zipfile.py", line 1699, in _extract_member    member = self.getinfo(member)             ^^^^^^^^^^^^^^^^^^^^  File "/home/moggi/devel/envs/python311/lib/python3.11/zipfile.py", line 1473, in getinfo    raise KeyError(KeyError: "There is no item named 'data/' in the archive"

If this is the expected new behavior I think the documentation for 3.10 should mention this breaking change and thezipfile.Path documentation might need an entry about this problem.

Thezipfile.Path object is used in the original code to check if the "data/" directory exists in the zip file.

Linked PRs

Metadata

Metadata

Assignees

Labels

3.10only security fixes3.11only security fixes3.12only security fixesstdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp