Skip to content

Commit ba687d9

Browse files
authored
pythongh-121735: Fix module-adjacent references in zip files (python#123037)
* pythongh-116608: Apply style and compatibility changes from importlib_metadata. * pythongh-121735: Ensure module-adjacent resources are loadable from a zipfile. * pythongh-121735: Allow all modules to be processed by the ZipReader. * Add blurb * Remove update-zips script, unneeded. * Remove unnecessary references to removed static fixtures. * Remove zipdata fixtures, unused.
1 parent 3bd942f commit ba687d9

40 files changed

+223
-261
lines changed

.gitattributes

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ Lib/test/cjkencodings/* noeol
2727
Lib/test/tokenizedata/coding20731.py noeol
2828
Lib/test/decimaltestdata/*.decTest noeol
2929
Lib/test/test_email/data/*.txt noeol
30-
Lib/test/test_importlib/resources/data01/* noeol
31-
Lib/test/test_importlib/resources/namespacedata01/* noeol
3230
Lib/test/xmltestdata/* noeol
3331

3432
# Shell scripts should have LF even on Windows because of Cygwin

Lib/importlib/resources/readers.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ def files(self):
3434

3535
class ZipReader(abc.TraversableResources):
3636
def __init__(self, loader, module):
37-
_, _, name = module.rpartition('.')
38-
self.prefix = loader.prefix.replace('\\', '/') + name + '/'
37+
self.prefix = loader.prefix.replace('\\', '/')
38+
if loader.is_package(module):
39+
_, _, name = module.rpartition('.')
40+
self.prefix += name + '/'
3941
self.archive = loader.archive
4042

4143
def open_resource(self, resource):

Lib/test/test_importlib/resources/data01/__init__.py

Whitespace-only changes.
Binary file not shown.

Lib/test/test_importlib/resources/data01/subdirectory/__init__.py

Whitespace-only changes.

Lib/test/test_importlib/resources/data01/subdirectory/binary.file

Lines changed: 0 additions & 1 deletion
This file was deleted.
Binary file not shown.

Lib/test/test_importlib/resources/data01/utf-8.file

Lines changed: 0 additions & 1 deletion
This file was deleted.

Lib/test/test_importlib/resources/data02/__init__.py

Whitespace-only changes.

Lib/test/test_importlib/resources/data02/one/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)