diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2019-05-09 15:34:36 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2019-05-09 15:34:35 (GMT) |
commit | 33e067d6a237ced8fd2ead70a461025fd91239be (patch) | |
tree | f56fa5bd7fd75c19d3119803a268638ef5948322 /Lib/zipfile.py | |
parent | afd1e6d2f0f5aaf4030d13342809ec0915dedf81 (diff) | |
download | cpython-33e067d6a237ced8fd2ead70a461025fd91239be.zip cpython-33e067d6a237ced8fd2ead70a461025fd91239be.tar.gz cpython-33e067d6a237ced8fd2ead70a461025fd91239be.tar.bz2 |
Add support for .parent and .joinpath in zipfile.Path (#13213)
Diffstat (limited to 'Lib/zipfile.py')
-rw-r--r-- | Lib/zipfile.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/Lib/zipfile.py b/Lib/zipfile.py index 62475c7..8f8cb86 100644 --- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -2218,12 +2218,14 @@ class Path: def __repr__(self): return self.__repr.format(self=self) - def __truediv__(self, add): + def joinpath(self, add): next = posixpath.join(self.at, add) next_dir = posixpath.join(self.at, add, "") names = self._names() return self._next(next_dir if next not in names and next_dir in names else next) + __truediv__ = joinpath + @staticmethod def _add_implied_dirs(names): return names + [ @@ -2232,6 +2234,13 @@ class Path: if name and name + "/" not in names ] + @property + def parent(self): + parent_at = posixpath.dirname(self.at) + if parent_at: + parent_at += '/' + return self._next(parent_at) + def _names(self): return self._add_implied_dirs(self.root.namelist()) |