aboutsummaryrefslogtreecommitdiffstats
path: root/bsie/reader/document/_plain.py
diff options
context:
space:
mode:
authorMatthias Baumgartner <dev@igsor.net>2023-07-28 11:31:24 +0200
committerMatthias Baumgartner <dev@igsor.net>2023-07-28 11:31:24 +0200
commit11b26a913d39edb7f36cd0a3b3d8e74c96738579 (patch)
tree463af082c0b77916c11a84263c96fc91ebedabed /bsie/reader/document/_plain.py
parent28e3640e0b5e03b50bf66711f46937f07a3d7fef (diff)
downloadbsie-11b26a913d39edb7f36cd0a3b3d8e74c96738579.tar.gz
bsie-11b26a913d39edb7f36cd0a3b3d8e74c96738579.tar.bz2
bsie-11b26a913d39edb7f36cd0a3b3d8e74c96738579.zip
document digestion:
* plaintext reader * text metrics extractor * text summary extractor
Diffstat (limited to 'bsie/reader/document/_plain.py')
-rw-r--r--bsie/reader/document/_plain.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/bsie/reader/document/_plain.py b/bsie/reader/document/_plain.py
new file mode 100644
index 0000000..a589265
--- /dev/null
+++ b/bsie/reader/document/_plain.py
@@ -0,0 +1,38 @@
+
+# standard imports
+import typing
+
+# bsie imports
+from bsie.utils import errors, filematcher
+
+# inner-module imports
+from .. import base
+
+# constants
+MATCH_RULE = 'mime=text/plain'
+
+# exports
+__all__: typing.Sequence[str] = (
+ 'Plain',
+ )
+
+
+## code ##
+
+class Plain(base.Reader):
+
+ _match: filematcher.Matcher
+
+ def __init__(self):
+ self._match = filematcher.parse(MATCH_RULE)
+
+ def __call__(self, path: str) -> typing.Sequence[str]:
+ # perform quick checks first
+ if not self._match(path):
+ raise errors.UnsupportedFileFormatError(path)
+
+ # open file in text mode
+ with open(path, 'rt') as ifile:
+ return [line.strip() for line in ifile.read().split('\n') if len(line.strip()) > 0]
+
+## EOF ##