fix: resolve all pre-existing ruff lint errors
Fix E501 line-too-long in backlog.py, network.py, test_network.py. Fix F541 f-string-without-placeholders in network.py. Fix I001 unsorted imports in network.py. Remove unused datetime import in test_cert.py (F401). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -187,7 +187,8 @@ class Backlog:
|
|||||||
"""
|
"""
|
||||||
assert self._db is not None
|
assert self._db is not None
|
||||||
await self._db.execute(
|
await self._db.execute(
|
||||||
"INSERT INTO nickserv_creds (network, nick, password, email, registered_at, host, status, verify_url) "
|
"INSERT INTO nickserv_creds "
|
||||||
|
"(network, nick, password, email, registered_at, host, status, verify_url) "
|
||||||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?) "
|
"VALUES (?, ?, ?, ?, ?, ?, ?, ?) "
|
||||||
"ON CONFLICT(network, nick) DO UPDATE SET "
|
"ON CONFLICT(network, nick) DO UPDATE SET "
|
||||||
"password = excluded.password, email = excluded.email, "
|
"password = excluded.password, email = excluded.email, "
|
||||||
@@ -231,7 +232,10 @@ class Backlog:
|
|||||||
async def get_nickserv_creds_by_host(
|
async def get_nickserv_creds_by_host(
|
||||||
self, network: str, host: str
|
self, network: str, host: str
|
||||||
) -> tuple[str, str] | None:
|
) -> tuple[str, str] | None:
|
||||||
"""Get stored verified NickServ nick and password by host. Returns (nick, password) or None."""
|
"""Get stored verified NickServ nick and password by host.
|
||||||
|
|
||||||
|
Returns (nick, password) or None.
|
||||||
|
"""
|
||||||
assert self._db is not None
|
assert self._db is not None
|
||||||
cursor = await self._db.execute(
|
cursor = await self._db.execute(
|
||||||
"SELECT nick, password FROM nickserv_creds "
|
"SELECT nick, password FROM nickserv_creds "
|
||||||
|
|||||||
@@ -492,7 +492,7 @@ class Network:
|
|||||||
Called immediately after SASL PLAIN success so the fingerprint is
|
Called immediately after SASL PLAIN success so the fingerprint is
|
||||||
registered before a potential K-line disconnects us.
|
registered before a potential K-line disconnects us.
|
||||||
"""
|
"""
|
||||||
from bouncer.cert import fingerprint, has_cert, cert_path
|
from bouncer.cert import cert_path, fingerprint, has_cert
|
||||||
|
|
||||||
nick = self._sasl_nick or self.nick
|
nick = self._sasl_nick or self.nick
|
||||||
if not has_cert(self.data_dir, self.cred_network, nick):
|
if not has_cert(self.data_dir, self.cred_network, nick):
|
||||||
@@ -594,14 +594,19 @@ class Network:
|
|||||||
)
|
)
|
||||||
if creds:
|
if creds:
|
||||||
stored_nick, stored_pass = creds
|
stored_nick, stored_pass = creds
|
||||||
log.info("[%s] found stored creds for nick %s, switching", self.cfg.name, stored_nick)
|
log.info("[%s] found stored creds for nick %s, switching",
|
||||||
|
self.cfg.name, stored_nick)
|
||||||
# Switch to the registered nick first
|
# Switch to the registered nick first
|
||||||
self._nick_confirmed.clear()
|
self._nick_confirmed.clear()
|
||||||
await self.send_raw("NICK", stored_nick)
|
await self.send_raw("NICK", stored_nick)
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(self._nick_confirmed.wait(), timeout=self.bouncer_cfg.nick_timeout)
|
await asyncio.wait_for(
|
||||||
|
self._nick_confirmed.wait(),
|
||||||
|
timeout=self.bouncer_cfg.nick_timeout,
|
||||||
|
)
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
log.warning("[%s] nick change to %s not confirmed", self.cfg.name, stored_nick)
|
log.warning("[%s] nick change to %s not confirmed",
|
||||||
|
self.cfg.name, stored_nick)
|
||||||
|
|
||||||
self._nickserv_password = stored_pass
|
self._nickserv_password = stored_pass
|
||||||
self._nickserv_pending = "identify"
|
self._nickserv_pending = "identify"
|
||||||
@@ -687,7 +692,7 @@ class Network:
|
|||||||
return
|
return
|
||||||
|
|
||||||
if "you are now logged in" in lower:
|
if "you are now logged in" in lower:
|
||||||
self._status(f"Q auth successful")
|
self._status("Q auth successful")
|
||||||
log.info("[%s] Q AUTH succeeded", self.cfg.name)
|
log.info("[%s] Q AUTH succeeded", self.cfg.name)
|
||||||
self._nickserv_pending = ""
|
self._nickserv_pending = ""
|
||||||
# Switch to configured nick if set
|
# Switch to configured nick if set
|
||||||
@@ -695,7 +700,10 @@ class Network:
|
|||||||
self._nick_confirmed.clear()
|
self._nick_confirmed.clear()
|
||||||
await self.send_raw("NICK", self.cfg.nick)
|
await self.send_raw("NICK", self.cfg.nick)
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(self._nick_confirmed.wait(), timeout=self.bouncer_cfg.nick_timeout)
|
await asyncio.wait_for(
|
||||||
|
self._nick_confirmed.wait(),
|
||||||
|
timeout=self.bouncer_cfg.nick_timeout,
|
||||||
|
)
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
log.warning("[%s] nick change to %s not confirmed",
|
log.warning("[%s] nick change to %s not confirmed",
|
||||||
self.cfg.name, self.cfg.nick)
|
self.cfg.name, self.cfg.nick)
|
||||||
@@ -798,7 +806,7 @@ class Network:
|
|||||||
self._nickserv_pending = ""
|
self._nickserv_pending = ""
|
||||||
await self._nickserv_register()
|
await self._nickserv_register()
|
||||||
elif "too soon" in lower or "wait" in lower or "too many" in lower:
|
elif "too soon" in lower or "wait" in lower or "too many" in lower:
|
||||||
self._status(f"REGISTER rejected (too soon/rate limited)")
|
self._status("REGISTER rejected (too soon/rate limited)")
|
||||||
log.warning("[%s] NickServ rate limited: %s", self.cfg.name, text)
|
log.warning("[%s] NickServ rate limited: %s", self.cfg.name, text)
|
||||||
self._nickserv_pending = ""
|
self._nickserv_pending = ""
|
||||||
await self._nickserv_complete()
|
await self._nickserv_complete()
|
||||||
@@ -837,7 +845,7 @@ class Network:
|
|||||||
url = match.group(1)
|
url = match.group(1)
|
||||||
token = url.rsplit("/verify/", 1)[-1] if "/verify/" in url else ""
|
token = url.rsplit("/verify/", 1)[-1] if "/verify/" in url else ""
|
||||||
log.info("[%s] visiting verification URL: %s", self.cfg.name, url)
|
log.info("[%s] visiting verification URL: %s", self.cfg.name, url)
|
||||||
self._status(f"visiting verification URL...")
|
self._status("visiting verification URL...")
|
||||||
try:
|
try:
|
||||||
import aiohttp
|
import aiohttp
|
||||||
from aiohttp_socks import ProxyConnector
|
from aiohttp_socks import ProxyConnector
|
||||||
@@ -1005,7 +1013,10 @@ class Network:
|
|||||||
self._nick_confirmed.clear()
|
self._nick_confirmed.clear()
|
||||||
await self.send_raw("NICK", p_nick)
|
await self.send_raw("NICK", p_nick)
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(self._nick_confirmed.wait(), timeout=self.bouncer_cfg.nick_timeout)
|
await asyncio.wait_for(
|
||||||
|
self._nick_confirmed.wait(),
|
||||||
|
timeout=self.bouncer_cfg.nick_timeout,
|
||||||
|
)
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
log.warning("[%s] could not switch to pending nick %s",
|
log.warning("[%s] could not switch to pending nick %s",
|
||||||
self.cfg.name, p_nick)
|
self.cfg.name, p_nick)
|
||||||
|
|||||||
@@ -91,7 +91,6 @@ class TestGenerateCert:
|
|||||||
assert fp1 != fp2 # New cert = new fingerprint
|
assert fp1 != fp2 # New cert = new fingerprint
|
||||||
|
|
||||||
def test_custom_validity_days(self, data_dir: Path) -> None:
|
def test_custom_validity_days(self, data_dir: Path) -> None:
|
||||||
import datetime
|
|
||||||
from cryptography import x509 as x509_mod
|
from cryptography import x509 as x509_mod
|
||||||
pem = generate_cert(data_dir, "libera", "testnick", validity_days=365)
|
pem = generate_cert(data_dir, "libera", "testnick", validity_days=365)
|
||||||
cert_data = pem.read_bytes()
|
cert_data = pem.read_bytes()
|
||||||
|
|||||||
@@ -324,7 +324,8 @@ class TestHandleWelcome:
|
|||||||
writer.drain = AsyncMock()
|
writer.drain = AsyncMock()
|
||||||
net._writer = writer
|
net._writer = writer
|
||||||
|
|
||||||
await net._handle(_msg(":server 001 coolguy :Welcome to the network coolguy!user@host.example.com"))
|
welcome = ":server 001 coolguy :Welcome to the network coolguy!user@host.example.com"
|
||||||
|
await net._handle(_msg(welcome))
|
||||||
assert net.nick == "coolguy"
|
assert net.nick == "coolguy"
|
||||||
assert net.state == State.PROBATION
|
assert net.state == State.PROBATION
|
||||||
|
|
||||||
@@ -337,7 +338,8 @@ class TestHandleWelcome:
|
|||||||
writer.drain = AsyncMock()
|
writer.drain = AsyncMock()
|
||||||
net._writer = writer
|
net._writer = writer
|
||||||
|
|
||||||
await net._handle(_msg(":server 001 nick :Welcome to the IRC Network nick!user@visible.host.com"))
|
welcome = ":server 001 nick :Welcome to the IRC Network nick!user@visible.host.com"
|
||||||
|
await net._handle(_msg(welcome))
|
||||||
assert net.visible_host == "visible.host.com"
|
assert net.visible_host == "visible.host.com"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user