aboutsummaryrefslogtreecommitdiff
path: root/webmentions_ssg/models.py
diff options
context:
space:
mode:
authorDennis Fink2026-11-12 22:07:12 +0100
committerDennis Fink2026-11-12 22:07:12 +0100
commitc7993952c585b66acad5275e39dbf91cf662b975 (patch)
tree976b3746444b3bd0bbb269bef9197c8b6a2e1696 /webmentions_ssg/models.py
parentb930b4425b91aa42abcec6c3443685065a5ca242 (diff)
downloadwebmentions-ssg-c7993952c585b66acad5275e39dbf91cf662b975.tar.gz
webmentions-ssg-c7993952c585b66acad5275e39dbf91cf662b975.zip
chore(core): enable stricter Ruff lint rules
Expand Ruff checks for bugbear, complexity, pathlib, return statements, simplifications, upgrades, and docstring style. Apply the resulting behavior-neutral cleanup across application and test code.
Diffstat (limited to 'webmentions_ssg/models.py')
-rw-r--r--webmentions_ssg/models.py61
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.