Compare commits
4 Commits
ad7ef32c38
...
d3799efeb3
| Author | SHA1 | Date | |
|---|---|---|---|
| d3799efeb3 | |||
| 8e8bc6345c | |||
| 87d8be2fda | |||
| 514eb99302 |
@ -94,10 +94,11 @@ class Message():
|
||||
question: Question
|
||||
answer: Optional[Answer]
|
||||
tags: Optional[set[Tag]]
|
||||
path: Optional[pathlib.Path]
|
||||
file_path: Optional[pathlib.Path]
|
||||
file_suffixes: list[str] = ['.txt', '.yaml']
|
||||
|
||||
# @classmethod
|
||||
# def from_file(cls: Type[MessageInst], path: pathlib.Path) -> MessageInst:
|
||||
# def from_file(cls: Type[MessageInst], file_path: pathlib.Path) -> MessageInst:
|
||||
# """
|
||||
# Create a Message from the given file. Expects the following file structure:
|
||||
# * TagLine (from 'self.tags')
|
||||
@ -105,9 +106,15 @@ class Message():
|
||||
# * Question
|
||||
# * Answer.Header
|
||||
# """
|
||||
# if file_path:
|
||||
# self.file_path = file_path
|
||||
# if not self.file_path:
|
||||
# raise MessageError("Got no valid path to read message")
|
||||
# if self.file_path.suffix not in self.file_suffixes:
|
||||
# raise MessageError(f"File type '{self.file_path.suffix}' is not supported")
|
||||
# pass
|
||||
|
||||
def to_file(self, path: Optional[pathlib.Path]) -> None:
|
||||
def to_file(self, file_path: Optional[pathlib.Path]) -> None:
|
||||
"""
|
||||
Write Message to the given file. Creates the following file structure:
|
||||
* TagLine (from 'self.tags')
|
||||
@ -116,8 +123,12 @@ class Message():
|
||||
* Answer.Header
|
||||
* Answer
|
||||
"""
|
||||
if not path and not self.path:
|
||||
raise MessageError('Got no valid path to write message')
|
||||
if file_path:
|
||||
self.file_path = file_path
|
||||
if not self.file_path:
|
||||
raise MessageError("Got no valid path to write message")
|
||||
if self.file_path.suffix not in self.file_suffixes:
|
||||
raise MessageError(f"File type '{self.file_path.suffix}' is not supported")
|
||||
pass
|
||||
|
||||
def asdict(self) -> dict[str, Any]:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user