diff options
Diffstat (limited to '')
| -rw-r--r-- | webmentions_ssg/models.py | 61 |
1 files changed, 20 insertions, 41 deletions
diff --git a/webmentions_ssg/models.py b/webmentions_ssg/models.py index 9442309..48d8532 100644 --- a/webmentions_ssg/models.py +++ b/webmentions_ssg/models.py @@ -43,9 +43,7 @@ class ReceivedStatus(StrEnum): class SentWebmentionStatus(StrEnum): - """ - Represent the outcome of a Webmention send attempt. - """ + """Represent the outcome of a Webmention send attempt.""" SENT = "sent" UNSUPPORTED = "unsupported" @@ -53,9 +51,7 @@ class SentWebmentionStatus(StrEnum): class User(UserMixin, Base): - """ - Represent an authenticated application user. - """ + """Represent an authenticated application user.""" __tablename__ = "users" @@ -64,8 +60,7 @@ class User(UserMixin, Base): password_hash: Mapped[str] = mapped_column(Text(), nullable=False) def __repr__(self) -> str: - """ - Return a developer-readable representation of the user. + """Return a developer-readable representation of the user. :return: Representation containing the username. """ @@ -73,8 +68,7 @@ class User(UserMixin, Base): @property def password(self) -> Never: - """ - Prevent access to the user's plain-text password. + """Prevent access to the user's plain-text password. :raises AttributeError: Always, because the password is write-only. """ @@ -82,8 +76,7 @@ class User(UserMixin, Base): @password.setter def password(self, password: str) -> None: - """ - Hash and store a new password. + """Hash and store a new password. :param password: Plain-text password to hash. """ @@ -100,8 +93,7 @@ class User(UserMixin, Base): return f"{self.id}:{fingerprint}" def check_password(self, password: str) -> bool: - """ - Check a plain-text password against the stored password hash. + """Check a plain-text password against the stored password hash. :param password: Plain-text password to check. :return: Whether the password matches the stored hash. @@ -110,9 +102,7 @@ class User(UserMixin, Base): class ReceivedWebmention(Base): - """ - Represent a Webmention received for verification. - """ + """Represent a Webmention received for verification.""" __tablename__ = "received_webmentions" @@ -159,8 +149,7 @@ class ReceivedWebmention(Base): ) def __repr__(self) -> str: - """ - Return a developer-readable representation of the received Webmention. + """Return a developer-readable representation of the received Webmention. :return: Representation containing the identifier, source, and target. """ @@ -186,8 +175,7 @@ class ReceivedWebmention(Base): @property def verified(self) -> bool: - """ - Return whether the Webmention has been successfully verified. + """Return whether the Webmention has been successfully verified. :return: Whether the Webmention status is ``verified``. """ @@ -195,8 +183,7 @@ class ReceivedWebmention(Base): @property def created_at(self) -> datetime: - """ - Return the creation time encoded in the Webmention UUID. + """Return the creation time encoded in the Webmention UUID. :return: Creation time as a timezone-aware datetime. """ @@ -204,9 +191,7 @@ class ReceivedWebmention(Base): class Source(Base): - """ - Represent a generated source document containing outgoing Webmentions. - """ + """Represent a generated source document containing outgoing Webmentions.""" __tablename__ = "sources" @@ -235,8 +220,7 @@ class Source(Base): ) def __repr__(self) -> str: - """ - Return a developer-readable representation of the source. + """Return a developer-readable representation of the source. :return: Representation containing the identifier and public URL. """ @@ -244,8 +228,7 @@ class Source(Base): @property def created_at(self) -> datetime: - """ - Return the creation time encoded in the source UUID. + """Return the creation time encoded in the source UUID. :return: Creation time as a timezone-aware datetime. """ @@ -253,9 +236,7 @@ class Source(Base): class SentWebmention(Base): - """ - Represent an outgoing Webmention associated with a source. - """ + """Represent an outgoing Webmention associated with a source.""" __tablename__ = "sent_webmentions" @@ -331,8 +312,7 @@ class SentWebmention(Base): ) def __repr__(self) -> str: - """ - Return a developer-readable representation of the sent Webmention. + """Return a developer-readable representation of the sent Webmention. :return: Representation containing the identifier and target URL. """ @@ -346,6 +326,7 @@ class SentWebmention(Base): self.active = active self.attempt_count = 0 self.next_retry_at = None + if resend: self.processed_revision = None self.status = None @@ -353,12 +334,12 @@ class SentWebmention(Base): self.endpoint = None self.response_status = None self.status_url = None + return self @property def pending(self) -> bool: - """ - Return whether the Webmention has an unprocessed source revision. + """Return whether the Webmention has an unprocessed source revision. :return: Whether the desired revision still requires processing. """ @@ -369,8 +350,7 @@ class SentWebmention(Base): @property def created_at(self) -> datetime: - """ - Return the creation time encoded in the Webmention UUID. + """Return the creation time encoded in the Webmention UUID. :return: Creation time as a timezone-aware datetime. """ @@ -378,8 +358,7 @@ class SentWebmention(Base): def uuid7_to_datetime(identifier: uuid.UUID) -> datetime: - """ - Convert a UUID version 7 timestamp to a datetime. + """Convert a UUID version 7 timestamp to a datetime. :param identifier: UUID whose embedded timestamp should be converted. :return: Timestamp as a timezone-aware UTC datetime. |
