8000 [3.12] gh-121735: Fix module-adjacent references in zip files · python/cpython@dde843d · GitHub
[go: up one dir, main page]

Skip to content

Commit dde843d

Browse files
committed
[3.12] gh-121735: Fix module-adjacent references in zip files
Applying the fix only and not the refactoring of the test suite.
1 parent 4514998 commit dde843d

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

Lib/importlib/resources/readers.py

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

3232
class ZipReader(abc.TraversableResources):
3333
def __init__(self, loader, module):
34-
_, _, name = module.rpartition('.')
35-
self.prefix = loader.prefix.replace('\\', '/') + name + '/'
34+
self.prefix = loader.prefix.replace('\\', '/')
35+
if loader.is_package(module):
36+
_, _, name = module.rpartition('.')
37+
self.prefix += name + '/'
3638
self.archive = loader.archive
3739

3840
def open_resource(self, resource):

Lib/zipimport.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -254,17 +254,9 @@ def load_module(self, fullname):
254254

255255

256256
def get_resource_reader(self, fullname):
257-
"""Return the ResourceReader for a package in a zip file.
258-
259-
If 'fullname' is a package within the zip file, return the
260-
'ResourceReader' object for the package. Otherwise return None.
261-
"""
262-
try:
263-
if not self.is_package(fullname):
264-
return None
265-
except ZipImportError:
266-
return None
257+
"""Return the ResourceReader for a module in a zip file."""
267258
from importlib.readers import ZipReader
259+
268260
return ZipReader(self, fullname)
269261

270262

0 commit comments

Comments
 (0)
0