mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-40924: Ensure importlib.resources.path returns an extant path (GH-20857)
This commit is contained in:
parent
e67f7db3c3
commit
2fb5f038f2
3 changed files with 24 additions and 1 deletions
|
@ -7,11 +7,19 @@ class FileReader(abc.TraversableResources):
|
|||
def __init__(self, loader):
|
||||
self.path = pathlib.Path(loader.path).parent
|
||||
|
||||
def resource_path(self, resource):
|
||||
"""
|
||||
Return the file system path to prevent
|
||||
`resources.path()` from creating a temporary
|
||||
copy.
|
||||
"""
|
||||
return str(self.path.joinpath(resource))
|
||||
|
||||
def files(self):
|
||||
return self.path
|
||||
|
||||
|
||||
class ZipReader(FileReader):
|
||||
class ZipReader(abc.TraversableResources):
|
||||
def __init__(self, loader, module):
|
||||
_, _, name = module.rpartition('.')
|
||||
prefix = loader.prefix.replace('\\', '/') + name + '/'
|
||||
|
@ -28,3 +36,6 @@ class ZipReader(FileReader):
|
|||
# for non-existent paths.
|
||||
target = self.files().joinpath(path)
|
||||
return target.is_file() and target.exists()
|
||||
|
||||
def files(self):
|
||||
return self.path
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue