mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
gh-59110: zipimport: support namespace packages when no directory entry exists (GH-121233)
This commit is contained in:
parent
db1729143d
commit
17d5b9df10
4 changed files with 139 additions and 29 deletions
|
@ -155,6 +155,8 @@ class zipimporter(_bootstrap_external._LoaderBasics):
|
|||
toc_entry = self._get_files()[key]
|
||||
except KeyError:
|
||||
raise OSError(0, '', key)
|
||||
if toc_entry is None:
|
||||
return b''
|
||||
return _get_data(self.archive, toc_entry)
|
||||
|
||||
|
||||
|
@ -554,6 +556,20 @@ def _read_directory(archive):
|
|||
finally:
|
||||
fp.seek(start_offset)
|
||||
_bootstrap._verbose_message('zipimport: found {} names in {!r}', count, archive)
|
||||
|
||||
# Add implicit directories.
|
||||
for name in list(files):
|
||||
while True:
|
||||
i = name.rstrip(path_sep).rfind(path_sep)
|
||||
if i < 0:
|
||||
break
|
||||
name = name[:i + 1]
|
||||
if name in files:
|
||||
break
|
||||
files[name] = None
|
||||
count += 1
|
||||
_bootstrap._verbose_message('zipimport: added {} implicit directories in {!r}',
|
||||
count, archive)
|
||||
return files
|
||||
|
||||
# During bootstrap, we may need to load the encodings
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue