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:zipfile.Path’sglob() andrglob() are not documented #133360

Open
Labels
docsDocumentation in the Doc dir
@calestyo

Description

@calestyo

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 have1/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 aboutPathnot doing any such sanitisations).

Cheers,
Chris.

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    Status

    No status

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp