sorrow <lynx1...@gmail.com> added the comment:
Here's what I came up with: ```python class ZipPath(zipfile.Path): def __init__(self, root, at=""): super().__init__(root, at) if not at.startswith("/") and self.root.namelist()[0].startswith("/"): self.at = f"/{at}" def __repr__(self): return ( f"{self.__class__.__name__}({self.root.filename!r}, " f"{self.at.lstrip('/')!r})" ) def __str__(self): return posixpath.join(self.root.filename, self.at.lstrip("/")) def _is_child(self, path): return posixpath.dirname(path.at.strip("/")) == self.at.strip("/") def _next(self, at): return self.__class__(self.root, at) ``` Pretty simple. The main things are going on in `__init__` and `_is_child` methods. These changes are enough for `iteritems()` to work. I decided to include the leading slash in the `at`, but strip it for the outside world (__str__ and __repr__). Also, I had to override the `_next` method because it makes `Path` objects no matter what class it's called from. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue41035> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com