Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
Description
Documentation
It seems documentation forzipfile.Path
’sglob()
andrglob()
is missing (or maybe they're meant to be private but wrongly "exported"?!
Also, the behaviour ofrglob()
seems a bit unexpected:
Assume the following test zip file:
1/1/a1/b1/c1/1/1/1/loop1/2/1/2/a1/2/b1/2/c1/3/2/2/f3/3/g.dir/.dir/a/.dir/a/1.dir/.1.dir/.d.file
where pathnames ending in/
are directories andloop
is a symlink to../../1
.
With:
p = zipfile.Path("test.zip")
glob()
does not allow an empty pattern:
i = p.glob("")Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python3.13/zipfile/_path/__init__.py", line 419, in glob raise ValueError(f"Unacceptable pattern: {pattern!r}")ValueError: Unacceptable pattern: ''
Butrglob()
does:
>>> for i in p.rglob(""):... print(i)test.zip/1/test.zip/1/1/test.zip/1/2/test.zip/1/3/test.zip/2/test.zip/3/test.zip/.dir/test.zip/.dir/a/
in which case it seems to list only directories.
If using*
as pattern:
>>> for i in p.rglob("*"):... print(i)test.zip/1/atest.zip/1/btest.zip/1/ctest.zip/1/1/test.zip/1/1/looptest.zip/1/2/test.zip/1/2/atest.zip/1/2/btest.zip/1/2/ctest.zip/1/3/test.zip/2/ftest.zip/3/gtest.zip/.dir/a/test.zip/.dir/a/1test.zip/.dir/.1test.zip/.dir/.d
the results are also a bit... unexpected...
.
files are included (which is at least not compatible with POSIX pattern matching notation on pathnames)- some but not all directories are given, e.g. we have
1/1/
but not1/
, which we did get when the pattern is the empty string. - documentation should also note, that the zip file name is for some reason prepended.
It's also not really clear whether these two functions are safe at all,... e.g. could they be used to break out of traversing the ZIP's contents with some tricky..
(cause at some point the docs warn aboutPath
not doing any such sanitisations).
Cheers,
Chris.
Metadata
Metadata
Assignees
Projects
Status
Status