diff options
author | Matthias Baumgartner <dev@igsor.net> | 2022-10-31 12:21:37 +0100 |
---|---|---|
committer | Matthias Baumgartner <dev@igsor.net> | 2022-10-31 12:21:37 +0100 |
commit | ce848b215086bd8d0f3e67a25a08239386b11ddb (patch) | |
tree | 68b1eaba6c2b702dc51e15a6e273b845ef251c89 /bsie/base/reader.py | |
parent | cb49e4567a18de6851286ff672e54f9a91865fe9 (diff) | |
parent | d2b4a528465dc01e8db92b61293c458c7911a333 (diff) | |
download | bsie-ce848b215086bd8d0f3e67a25a08239386b11ddb.tar.gz bsie-ce848b215086bd8d0f3e67a25a08239386b11ddb.tar.bz2 bsie-ce848b215086bd8d0f3e67a25a08239386b11ddb.zip |
Merge branch 'mb/arch' into develop
Diffstat (limited to 'bsie/base/reader.py')
-rw-r--r-- | bsie/base/reader.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/bsie/base/reader.py b/bsie/base/reader.py new file mode 100644 index 0000000..f29e451 --- /dev/null +++ b/bsie/base/reader.py @@ -0,0 +1,48 @@ +"""The Reader classes return high-level content structures from files. + +The Reader fulfills two purposes: + First, it brokers between multiple libraries and file formats. + Second, it separates multiple aspects of a file into distinct content types. + +Part of the bsie module. +A copy of the license is provided with the project. +Author: Matthias Baumgartner, 2022 +""" +# imports +import abc +import typing + +# inner-module imports +from bsie.utils.bsfs import URI, typename + +# exports +__all__: typing.Sequence[str] = ( + 'Aggregator', + 'Reader', + ) + + +## code ## + +class Reader(abc.ABC): + """Read and return some content from a file.""" + + # In what data structure content is returned + CONTENT_TYPE = typing.Union[typing.Any] + # NOTE: Child classes must also assign a typing.Union even if there's + # only one options + + def __str__(self) -> str: + return typename(self) + + def __repr__(self) -> str: + return f'{typename(self)}()' + + # FIXME: How about using contexts instead of calls? + @abc.abstractmethod + def __call__(self, path: URI) -> CONTENT_TYPE: + """Return some content of the file at *path*. + Raises a `ReaderError` if the reader cannot make sense of the file format. + """ + +## EOF ## |