Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

GH-130614: Add test suites for readable and writable pathlib paths #130648

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

Closed
wants to merge 8 commits into from
Closed
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
ReadableZipPath: handle leading slashes slightly more robustly
  • Loading branch information
barneygale committed Feb 27, 2025
commit 0601addd366e09c67c1ce3105dfb3ed47b00bb9c
18 changes: 14 additions & 4 deletions 18 Lib/test/test_pathlib/support/zip_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,14 @@ class ZipFileList:
`resolve()` method fetches an entry from the tree.
"""

__slots__ = ('_root_info', '_items')
__slots__ = ('_roots', '_items')

def __init__(self, items):
self._root_info = ZipPathInfo()
self._roots = {
'': ZipPathInfo(),
'/': ZipPathInfo(),
'//': ZipPathInfo(),
}
self._items = []
for item in items:
self.append(item)
Expand All @@ -80,7 +84,8 @@ def resolve(self, path, create=False):
"""
Returns a PathInfo object for the given path by walking the tree.
"""
path_info = self._root_info
_drive, root, path = posixpath.splitroot(path)
path_info = self._roots[root]
for name in path.split('/'):
if not name or name == '.':
pass
Expand Down Expand Up @@ -127,7 +132,12 @@ def with_segments(self, *pathsegments):
return type(self)(*pathsegments, zip_file=self.zip_file)

def __open_rb__(self, buffering=-1):
return self.zip_file.open(str(self), 'r')
info = self.info
if not info.exists():
raise FileNotFoundError(errno.ENOENT, "File not found", self)
elif info.is_dir():
raise IsADirectoryError(errno.EISDIR, "Is a directory", self)
return self.zip_file.open(info.zip_info, 'r')

def iterdir(self):
info = self.info
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.