[3.9] bpo-40924: Revert "bpo-39791 native hooks for importlib.resources.files (GH-20576)" (#20760)

This reverts commit 9cf1be46e3 due to
https://bugs.python.org/issue40924.
This commit is contained in:
Łukasz Langa 2020-06-09 19:50:01 +02:00 committed by GitHub
parent 6cb24a035c
commit ce5e6f098f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 2369 additions and 2123 deletions

View file

@ -982,10 +982,32 @@ class FileLoader:
with _io.FileIO(path, 'r') as file:
return file.read()
# ResourceReader ABC API.
@_check_name
def get_resource_reader(self, module):
from importlib.readers import FileReader
return FileReader(self)
if self.is_package(module):
return self
return None
def open_resource(self, resource):
path = _path_join(_path_split(self.path)[0], resource)
return _io.FileIO(path, 'r')
def resource_path(self, resource):
if not self.is_resource(resource):
raise FileNotFoundError
path = _path_join(_path_split(self.path)[0], resource)
return path
def is_resource(self, name):
if path_sep in name:
return False
path = _path_join(_path_split(self.path)[0], name)
return _path_isfile(path)
def contents(self):
return iter(_os.listdir(_path_split(self.path)[0]))
class SourceFileLoader(FileLoader, SourceLoader):