_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
}
+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