8000 bpo-44095: Add suffix, stem and suffixes to zipfile.Path by miguendes · Pull Request #26129 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-44095: Add suffix, stem and suffixes to zipfile.Path #26129

New issue 8000

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add suffix
  • Loading branch information
miguendes committed May 14, 2021
commit c482e560d15f50fa2bef95ea6da7fb720dcfeb1c
19 changes: 19 additions & 0 deletions Lib/test/test_zipfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3093,6 +3093,25 @@ def test_root_name(self, alpharep):
root = zipfile.Path(alpharep)
assert root.name == 'alpharep.zip' == root.filename.name

@pass_alpharep
def test_suffix(self, alpharep):
"""
The suffix of the root should be the suffix of the zipfile.
The suffix of each nested file is the final component's last suffix, if any.
Includes the leading period, just like pathlib.Path.
"""
root = zipfile.Path(alpharep)
assert root.suffix == '.zip' == root.filename.suffix

b = root / "b.txt"
assert b.suffix == ".txt"

c = root / "c" / "filename.tar.gz"
assert c.suffix == ".gz"

d = root / "d"
assert d.suffix == ""

@pass_alpharep
def test_root_parent(self, alpharep):
root = zipfile.Path(alpharep)
9624 Expand Down
4 changes: 4 additions & 0 deletions Lib/zipfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2342,6 +2342,10 @@ def open(self, mode='r', *args, pwd=None, **kwargs):
def name(self):
return pathlib.Path(self.at).name or self.filename.name

@property
def suffix(self):
return pathlib.Path(self.at).suffix or self.filename.suffix

@property
def filename(self):
return pathlib.Path(self.root.filename).joinpath(self.at)
Expand Down
0