mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
Implement the get_resource_reader() API for file system imports (#5168)
This commit is contained in:
parent
21102f0dc2
commit
5ec0feeeec
6 changed files with 1356 additions and 1263 deletions
|
@ -59,8 +59,10 @@ def _get_resource_reader(
|
|||
# hook wants to create a weak reference to the object, but
|
||||
# zipimport.zipimporter does not support weak references, resulting in a
|
||||
# TypeError. That seems terrible.
|
||||
if hasattr(package.__spec__.loader, 'open_resource'):
|
||||
return cast(resources_abc.ResourceReader, package.__spec__.loader)
|
||||
spec = package.__spec__
|
||||
if hasattr(spec.loader, 'get_resource_reader'):
|
||||
return cast(resources_abc.ResourceReader,
|
||||
spec.loader.get_resource_reader(spec.name))
|
||||
return None
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue