gh-59110: zipimport: support namespace packages when no directory entry exists (GH-121233)

This commit is contained in:
Serhiy Storchaka 2024-07-04 18:04:24 +03:00 committed by GitHub
parent db1729143d
commit 17d5b9df10
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 139 additions and 29 deletions

View file

@ -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