home · contact · privacy
Depend _Textfiled on _Lookupable for its new cls(db=…) requirement. master
authorPlom Heller <plom@plomlompom.com>
Sun, 4 Oct 2026 17:45:32 +0000 (19:45 +0200)
committerPlom Heller <plom@plomlompom.com>
Sun, 4 Oct 2026 17:45:32 +0000 (19:45 +0200)
src/bricksplom/misc.py

index 61a1d9d1ca2280560515faa80849bbbcbd1244ea..0091b0751145598ffe7c853ab91b8f1b9c6f1e08 100644 (file)
@@ -55,56 +55,6 @@ _PageColumn = tuple[_BrickListing, ...]
 _Page = tuple[_PageColumn, ...]
 
 
-class _Textfiled(ABC):
-    'Table to be read from textfile, and compatible output in .raw().'
-
-    @staticmethod
-    def lines_of(
-            path: tuple[str, str]
-            ) -> tuple[str, ...]:
-        'Non-empty right-stripped lines of file at path.'
-        joined_path = Path(path[0]).joinpath(path[1])
-        return tuple(line.rstrip()
-                     for line in joined_path.read_text(encoding='utf8'
-                                                       ).split(CHAR_NEWLINE)
-                     if line.strip() and not line.startswith(_CHAR_COMMENT))
-
-    @staticmethod
-    def tokify(
-            body: str,
-            len_expected: int
-            ) -> tuple[str, ...]:
-        'Body parsed into left-stripped tokens of len_expected count.'
-        collected: list[str] = []
-        while len(collected) < len_expected:
-            body = body.lstrip()
-            if len(collected) == len_expected - 1:
-                tok = body
-            else:
-                assert _CHAR_SEP_TOKEN in body, body
-                tok, body = body.split(_CHAR_SEP_TOKEN, maxsplit=1)
-            collected += [tok]
-        return tuple(collected)
-
-    @classmethod
-    @abstractmethod
-    def from_textfile(
-            cls,
-            path: tuple[str, str],
-            db: 'BricksDb'
-            ) -> dict[str, Self]:
-        'Build from file at path.'
-
-    @abstractmethod
-    def raw(self) -> str:
-        'Output in format used for reading in.'
-
-    def __str__(
-            self
-            ) -> str:
-        return self.raw()
-
-
 class _Lookupable:
     'Adds .db, provides methods for BricksDb.lookup and .id_ padding.'
     _id_indent: int = 0
@@ -224,6 +174,56 @@ class _Lookupable:
             }
 
 
+class _Textfiled(ABC, _Lookupable):
+    'Table to be read from textfile, and compatible output in .raw().'
+
+    @staticmethod
+    def lines_of(
+            path: tuple[str, str]
+            ) -> tuple[str, ...]:
+        'Non-empty right-stripped lines of file at path.'
+        joined_path = Path(path[0]).joinpath(path[1])
+        return tuple(line.rstrip()
+                     for line in joined_path.read_text(encoding='utf8'
+                                                       ).split(CHAR_NEWLINE)
+                     if line.strip() and not line.startswith(_CHAR_COMMENT))
+
+    @staticmethod
+    def tokify(
+            body: str,
+            len_expected: int
+            ) -> tuple[str, ...]:
+        'Body parsed into left-stripped tokens of len_expected count.'
+        collected: list[str] = []
+        while len(collected) < len_expected:
+            body = body.lstrip()
+            if len(collected) == len_expected - 1:
+                tok = body
+            else:
+                assert _CHAR_SEP_TOKEN in body, body
+                tok, body = body.split(_CHAR_SEP_TOKEN, maxsplit=1)
+            collected += [tok]
+        return tuple(collected)
+
+    @classmethod
+    @abstractmethod
+    def from_textfile(
+            cls,
+            path: tuple[str, str],
+            db: 'BricksDb'
+            ) -> dict[str, Self]:
+        'Build from file at path.'
+
+    @abstractmethod
+    def raw(self) -> str:
+        'Output in format used for reading in.'
+
+    def __str__(
+            self
+            ) -> str:
+        return self.raw()
+
+
 class _BrickColor(_Textfiled, _Lookupable):
     'Color incl. solidness/transparency field.'
     _id_indent = 3