Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 9 additions & 0 deletions Lib/test/test_zipfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3443,6 +3443,13 @@ def test_suffixes(self, alpharep):
e = root / '.hgrc'
assert e.suffixes == []

@pass_alpharep
def test_suffix_no_filename(self, alpharep):
alpharep.filename = None
root = zipfile.Path(alpharep)
assert root.joinpath('example').suffix == ""
assert root.joinpath('example').suffixes == []

@pass_alpharep
def test_stem(self, alpharep):
"""
Expand All @@ -3460,6 +3467,8 @@ def test_stem(self, alpharep):
d = root / "d"
assert d.stem == "d"

assert (root / ".gitignore").stem == ".gitignore"

@pass_alpharep
def test_root_parent(self, alpharep):
root = zipfile.Path(alpharep)
Expand Down
11 changes: 7 additions & 4 deletions Lib/zipfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2420,21 +2420,24 @@ def open(self, mode='r', *args, pwd=None, **kwargs):
encoding, args, kwargs = _extract_text_encoding(*args, **kwargs)
return io.TextIOWrapper(stream, encoding, *args, **kwargs)

def _base(self):
return pathlib.PurePosixPath(self.at or self.root.filename)

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

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

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

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

@property
def filename(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fixed several bug in zipfile.Path in
``name``/``suffix``/``suffixes``/``stem`` operations when no filename is
present and the Path is not at the root of the zipfile.