diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2020-06-29 16:59:22 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-29 22:59:22 +0200 |
commit | 2fb5f038f2a2e91a7293d62dfd5601e6eb500c55 (patch) | |
tree | 599ffdee6b55ed75c994e7072e21b1893b7dde79 /Lib/importlib/readers.py | |
parent | e67f7db3c34f70536f36c56bb82e33c3512a53a3 (diff) | |
download | cpython-git-2fb5f038f2a2e91a7293d62dfd5601e6eb500c55.tar.gz |
bpo-40924: Ensure importlib.resources.path returns an extant path (GH-20857)
Diffstat (limited to 'Lib/importlib/readers.py')
-rw-r--r-- | Lib/importlib/readers.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/Lib/importlib/readers.py b/Lib/importlib/readers.py index fb49ebe2b1..6331e4daf4 100644 --- a/Lib/importlib/readers.py +++ b/Lib/importlib/readers.py @@ -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 |