mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
[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:
parent
6cb24a035c
commit
ce5e6f098f
9 changed files with 2369 additions and 2123 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue