Skip to content

Commit

Permalink
Add the ResourceReader ABC
Browse files Browse the repository at this point in the history
  • Loading branch information
brettcannon committed Oct 27, 2017
1 parent 4d25546 commit f77ef54
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions importlib_resources/abc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import abc
from typing.io import BinaryIO


class ResourceReader(abc.ABC):

"""Abstract base class for loaders to provide resource reading support."""

@abc.abstractmethod
def open_resource(self, path: str) -> BinaryIO:
"""Return an opened, file-like object for binary reading of the resource.
The 'path' argument is expected to represent only a file name.
If the resource cannot be found, FileNotFoundError is raised.
"""
raise FileNotFoundError

def resource_path(self, path: str) -> str:
"""Return the file system path to the specified resource.
The 'path' argument is expected to represent only a file name.
If the resource does not exist on the file system, raise
FileNotFoundError.
"""
raise FileNotFoundError

0 comments on commit f77ef54

Please sign in to comment.