2022-05-05 14:31:59 +00:00
|
|
|
"""Document handling classes"""
|
|
|
|
|
|
|
|
from abc import ABC, abstractmethod
|
|
|
|
from datetime import datetime
|
|
|
|
from typing import Optional
|
|
|
|
|
|
|
|
from ..identity import Identity
|
|
|
|
from ..path import Path
|
|
|
|
|
|
|
|
|
|
|
|
class Document(ABC): # pragma: no cover pylint: disable=too-few-public-methods
|
|
|
|
"""Abstract base class for documents"""
|
|
|
|
|
|
|
|
path: Path
|
|
|
|
|
|
|
|
author: Identity
|
|
|
|
|
|
|
|
timestamp: datetime
|
|
|
|
|
2022-05-04 12:31:25 +00:00
|
|
|
signature: Optional[str]
|
2022-05-05 14:31:59 +00:00
|
|
|
|
2022-05-06 15:21:39 +00:00
|
|
|
@property
|
|
|
|
@abstractmethod
|
|
|
|
def content_length(self) -> int:
|
|
|
|
"""The length of the document"""
|
|
|
|
|
2022-05-05 14:31:59 +00:00
|
|
|
@abstractmethod
|
|
|
|
def sign(self, identity: Optional[Identity] = None) -> None:
|
|
|
|
"""Sign the document as identity
|
|
|
|
|
|
|
|
If ``identity`` is ``None``, use ``self.author`` instead.
|
|
|
|
"""
|
2022-05-09 05:50:58 +00:00
|
|
|
|
|
|
|
def __repr__(self) -> str:
|
|
|
|
return f'<{self.__class__.__name__} {self.path} by {self.author}>'
|