Skip to content

Commit 1394980

Browse files
committed
1 parent 6114970 commit 1394980

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

importlib_resources/abc.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,34 @@ def open(self, mode='r', *args, **kwargs):
116116
"""
117117

118118

119+
class ResourceReader:
120+
# Holds the string name of the virtual Python package this is a resource loader for.
121+
# For filesystems, this is effectively a reader for a directory at `fullname.replace('.', '/')`
122+
fullname = None
123+
124+
def child_readers(self) -> [ResourceReader]
125+
"""Obtain an iterable of ResourceReader for available child virtual packages of this one.
126+
127+
On filesystems, this essentially returns instances corresponding to immediate child directories.
128+
"""
129+
130+
def resources(self) -> [str]
131+
"""Obtain available named resources for this virtual package.
132+
133+
On filesystems, this essentially returns files in the current directory.
134+
TODO consider returning a special type that exposes an `open()`, etc.
135+
""""
136+
137+
def open_binary(self, resource) -> File
138+
"""Obtain a File-like for a named resource.
139+
140+
On filesystems, this attempts to open os.path.join(self, resource).
141+
142+
Attempting to open a non-resource entity (such as a subdirectory) or a missing
143+
resource raises NotAResourceError.
144+
"""
145+
146+
119147
class TraversableResources(ResourceReader):
120148
@abc.abstractmethod
121149
def files(self):

0 commit comments

Comments
 (0)