Skip to content

Commit

Permalink
[3.12] pythongh-121735: Fix module-adjacent references in zip files
Browse files Browse the repository at this point in the history
Applying the fix only and not the refactoring of the test suite.
  • Loading branch information
jaraco committed Sep 12, 2024
1 parent 4514998 commit dde843d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
6 changes: 4 additions & 2 deletions Lib/importlib/resources/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ def files(self):

class ZipReader(abc.TraversableResources):
def __init__(self, loader, module):
_, _, name = module.rpartition('.')
self.prefix = loader.prefix.replace('\\', '/') + name + '/'
self.prefix = loader.prefix.replace('\\', '/')
if loader.is_package(module):
_, _, name = module.rpartition('.')
self.prefix += name + '/'
self.archive = loader.archive

def open_resource(self, resource):
Expand Down
12 changes: 2 additions & 10 deletions Lib/zipimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,17 +254,9 @@ def load_module(self, fullname):


def get_resource_reader(self, fullname):
"""Return the ResourceReader for a package in a zip file.
If 'fullname' is a package within the zip file, return the
'ResourceReader' object for the package. Otherwise return None.
"""
try:
if not self.is_package(fullname):
return None
except ZipImportError:
return None
"""Return the ResourceReader for a module in a zip file."""
from importlib.readers import ZipReader

return ZipReader(self, fullname)


Expand Down

0 comments on commit dde843d

Please sign in to comment.