Implement the get_resource_reader() API for file system imports (#5168)

This commit is contained in:
Barry Warsaw 2018-01-15 15:07:11 -08:00 committed by GitHub
parent 21102f0dc2
commit 5ec0feeeec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 1356 additions and 1263 deletions

View file

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