Skip to content

Commit

Permalink
Add parent property
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed May 8, 2019
1 parent 5598095 commit 87b0394
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion zipp.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,15 @@ def __str__(self):
def __repr__(self):
return self.__repr.format(self=self)

def __truediv__(self, add):
def joinpath(self, add):
add = self._pathlib_compat(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 + [
Expand All @@ -155,6 +157,13 @@ def _add_implied_dirs(names):
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())

Expand Down

0 comments on commit 87b0394

Please sign in to comment.