summaryrefslogtreecommitdiff
path: root/Lib/importlib
diff options
context:
space:
mode:
authorBrett Cannon <brettcannon@users.noreply.github.com>2017-12-15 16:29:35 -0800
committerGitHub <noreply@github.com>2017-12-15 16:29:35 -0800
commit4ac5150e068a3a795ef00465f6dff51747b62b91 (patch)
treeb9e051b66549fae628764ca110a61fc1c153a827 /Lib/importlib
parentd2b02310acbfe6c978a8ad3cd3ac8b3f12927442 (diff)
downloadcpython-git-4ac5150e068a3a795ef00465f6dff51747b62b91.tar.gz
bpo-32248: Implement importlib.abc.ResourceReader (GH-4892)
Diffstat (limited to 'Lib/importlib')
-rw-r--r--Lib/importlib/abc.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/Lib/importlib/abc.py b/Lib/importlib/abc.py
index d7cadf2ee7..b772db3758 100644
--- a/Lib/importlib/abc.py
+++ b/Lib/importlib/abc.py
@@ -340,3 +340,41 @@ class SourceLoader(_bootstrap_external.SourceLoader, ResourceLoader, ExecutionLo
"""
_register(SourceLoader, machinery.SourceFileLoader)
+
+
+class ResourceReader(Loader):
+
+ """Abstract base class for loaders to provide resource reading support."""
+
+ @abc.abstractmethod
+ def open_resource(self, resource):
+ """Return an opened, file-like object for binary reading.
+
+ The 'resource' argument is expected to represent only a file name
+ and thus not contain any subdirectory components.
+
+ If the resource cannot be found, FileNotFoundError is raised.
+ """
+ raise FileNotFoundError
+
+ @abc.abstractmethod
+ def resource_path(self, resource):
+ """Return the file system path to the specified resource.
+
+ The 'resource' argument is expected to represent only a file name
+ and thus not contain any subdirectory components.
+
+ If the resource does not exist on the file system, raise
+ FileNotFoundError.
+ """
+ raise FileNotFoundError
+
+ @abc.abstractmethod
+ def is_resource(self, name):
+ """Return True if the named 'name' is consider a resource."""
+ raise FileNotFoundError
+
+ @abc.abstractmethod
+ def contents(self):
+ """Return an iterator of strings over the contents of the package."""
+ return iter([])