diff options
| author | Christophe Besson <cbesson@gmail.com> | 2026-09-19 14:24:13 +0200 |
|---|---|---|
| committer | Christophe Besson <cbesson@gmail.com> | 2026-09-19 14:24:13 +0200 |
| commit | 86188385cbdae1ee90c1dca7a7b9db2edef1ecd4 (patch) | |
| tree | cc01153f05e84ad6cd34556caecd3f4bc335d0bd /packages/meshbay-hub/src/meshbay_hub/mail.py | |
| parent | d2495a2c4b89fbbfc18cefec83ae96cabdd745e2 (diff) | |
| download | meshbay-86188385cbdae1ee90c1dca7a7b9db2edef1ecd4.tar.gz | |
style: ruff's own fixes, mechanically applied
`ruff check .` had gone unrun long enough to report 568 errors, which is the
same as having no linter: the next real finding would have been invisible in the
noise. This is the 521 it fixes by itself, in 173 files, and nothing else — the
98 it cannot fix are the next commit.
What actually changed: import sorting (225), imports nobody used (87, none of
them a re-export — no `__init__.py` is touched, which was the one way this could
have broken an import elsewhere), `datetime.timezone.utc` to `datetime.UTC` (69)
and `asyncio.TimeoutError` to `TimeoutError` (18), both plain aliases on the 3.12
this project requires, `Optional[X]` to `X | None` (24), and f-strings with
nothing to interpolate (19).
Checked rather than assumed: every module in the three packages still imports,
and the suite is 2893 passed — the same count, test for test, as the merge
before it.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/mail.py')
| -rw-r--r-- | packages/meshbay-hub/src/meshbay_hub/mail.py | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/mail.py b/packages/meshbay-hub/src/meshbay_hub/mail.py index 126ed45..1eb7c51 100644 --- a/packages/meshbay-hub/src/meshbay_hub/mail.py +++ b/packages/meshbay-hub/src/meshbay_hub/mail.py @@ -16,7 +16,7 @@ import asyncio import hashlib import logging import smtplib -from datetime import datetime, timedelta, timezone +from datetime import UTC, datetime, timedelta from email.message import EmailMessage log = logging.getLogger(__name__) @@ -79,7 +79,7 @@ async def _take(db, key: str, window: timedelta, ceiling: int, """ from meshbay_hub.db.models import MailQuota - now = datetime.now(timezone.utc) + now = datetime.now(UTC) row = await db.get(MailQuota, key) if row is None: row = MailQuota(key=key, window_start=now, count=0, last_sent=None) @@ -87,14 +87,14 @@ async def _take(db, key: str, window: timedelta, ceiling: int, started = row.window_start if started.tzinfo is None: - started = started.replace(tzinfo=timezone.utc) + started = started.replace(tzinfo=UTC) if now - started >= window: row.window_start, row.count = now, 0 if cooldown is not None and row.last_sent is not None: last = row.last_sent if last.tzinfo is None: - last = last.replace(tzinfo=timezone.utc) + last = last.replace(tzinfo=UTC) if now - last < cooldown: raise MailRefused("too soon since the last message to this recipient") @@ -131,12 +131,12 @@ async def _announce_exhaustion(scope: str) -> None: try: async with get_session_factory()() as db: key = f"alert:{scope}" - now = datetime.now(timezone.utc) + now = datetime.now(UTC) row = await db.get(MailQuota, key) if row is not None and row.last_sent is not None: last = row.last_sent if last.tzinfo is None: - last = last.replace(tzinfo=timezone.utc) + last = last.replace(tzinfo=UTC) if now - last < timedelta(hours=1): return if row is None: @@ -202,9 +202,10 @@ async def reserve(db, purpose: str, address: str) -> None: async def status(db) -> dict: """What the operator sees in the panel: is the hub still sending?""" + from sqlalchemy import func, select + from meshbay_hub import hub_settings from meshbay_hub.db.models import MailQuota - from sqlalchemy import func, select limits = await hub_settings.mail_limits(db) row = await db.get(MailQuota, "hour") @@ -213,8 +214,8 @@ async def status(db) -> dict: if row is not None: started = row.window_start if started.tzinfo is None: - started = started.replace(tzinfo=timezone.utc) - if datetime.now(timezone.utc) - started < timedelta(hours=1): + started = started.replace(tzinfo=UTC) + if datetime.now(UTC) - started < timedelta(hours=1): used, window_start = row.count, started.isoformat() recipients = await db.scalar( @@ -244,10 +245,11 @@ async def status(db) -> dict: async def purge_expired_quota(db) -> int: """Drop counters whose window has passed. Returns how many went.""" - from meshbay_hub.db.models import MailQuota from sqlalchemy import delete - cutoff = datetime.now(timezone.utc) - timedelta(days=1) + from meshbay_hub.db.models import MailQuota + + cutoff = datetime.now(UTC) - timedelta(days=1) result = await db.execute( delete(MailQuota).where(MailQuota.window_start < cutoff)) await db.commit() |