`zipfile`: `zipfile.Path`’s `glob()` and `rglob()` are not documented
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 35.9k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
Documentation
It seems documentation for zipfile.Path’s glob() and rglob() is missing (or maybe they're meant to be private but wrongly "exported"?!
Also, the behaviour of rglob() seems a bit unexpected:
Assume the following test zip file:
1/
1/a
1/b
1/c
1/1/
1/1/loop
1/2/
1/2/a
1/2/b
1/2/c
1/3/
2/
2/f
3/
3/g
.dir/
.dir/a/
.dir/a/1
.dir/.1
.dir/.d
.file
where pathnames ending in / are directories and loop 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: ''
But rglob() 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/a
test.zip/1/b
test.zip/1/c
test.zip/1/1/
test.zip/1/1/loop
test.zip/1/2/
test.zip/1/2/a
test.zip/1/2/b
test.zip/1/2/c
test.zip/1/3/
test.zip/2/f
test.zip/3/g
test.zip/.dir/a/
test.zip/.dir/a/1
test.zip/.dir/.1
test.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 about Path not doing any such sanitisations).
Cheers,
Chris.
Linked PRs
- gh-144460
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với zipfile.Path và các điểm vào glob() và rglob(), bao gồm đường dẫn triển khai được hiển thị là zipfile/_path/init.py. Xem lại các ví dụ đã được báo cáo về mẫu rỗng và '*', sau đó kiểm tra PR được liên kết gh-144460 và phần thảo luận. Công việc được xem là hoàn tất khi hành vi được tài liệu hóa, việc thêm tiền tố vào đường dẫn, kết quả thư mục, các tệp bắt đầu bằng dấu chấm và các vấn đề về an toàn đều đã được xác định và bao quát.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- documentation
- Loại issue
- Tài liệu
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Cần làm rõ
- Mức phù hợp với người mới
- 25/100