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

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
Prev Previous commit
Next Next commit
Add suffixes
  • Loading branch information
miguendes committed May 14, 2021
commit 65ded7cf50bd3550a458393aa5602e0c7721ccdc
22 changes: 22 additions & 0 deletions Lib/test/test_zipfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3112,6 +3112,28 @@ def test_suffix(self, alpharep):
d = root / "d"
assert d.suffix == ""

@pass_alpharep
def test_suffixes(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.suffixes == ['.zip'] == root.filename.suffixes

b = root / 'b.txt'
assert b.suffixes == ['.txt']

c = root / 'c' / 'filename.tar.gz'
assert c.suffixes == ['.tar', '.gz']

d = root / 'd'
assert d.suffixes == []

e = root / '.hgrc'
assert e.suffixes == []

@pass_alpharep
def test_stem(self, alpharep):
"""
Expand Down
4 changes: 4 additions & 0 deletions Lib/zipfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2346,6 +2346,10 @@ def name(self):
def suffix(self):
return pathlib.Path(self.at).suffix or self.filename.suffix

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

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