aboutsummaryrefslogtreecommitdiff
path: root/webmentions_ssg/net.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/net.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 '')
-rw-r--r--webmentions_ssg/net.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/webmentions_ssg/net.py b/webmentions_ssg/net.py
index 01a9a80..b88e2d8 100644
--- a/webmentions_ssg/net.py
+++ b/webmentions_ssg/net.py
@@ -110,21 +110,28 @@ class PublicNetworkBackend(httpcore.SyncBackend):
else socket.AF_INET
)
sock = socket.socket(family, socket.SOCK_STREAM)
+
try:
sock.settimeout(
self._deadline.timeout(timeout, httpcore.ConnectTimeout)
)
+
if local_address is not None:
sock.bind((local_address, 0))
+
for option in socket_options or ():
sock.setsockopt(*option)
+
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
+
# This numeric address is the *same* address just validated;
# no getaddrinfo or DNS resolver runs between check and connect.
sock.connect((address, port))
+
return DeadlineStream(SyncStream(sock), self._deadline)
except (TimeoutError, OSError) as exc:
sock.close()
+
if isinstance(exc, TimeoutError):
last_error = httpcore.ConnectTimeout(str(exc))
else:
@@ -157,6 +164,7 @@ def build_client(user_agent: str, *, accept: str | None = None) -> httpx.Client:
headers = {"User-Agent": user_agent}
if accept is not None:
headers["Accept"] = accept
+
return httpx.Client(
headers=headers,
timeout=httpx.Timeout(current_app.config["REQUEST_TIMEOUT"]),
@@ -225,8 +233,7 @@ def public_addresses(
def is_http_url(url: str) -> bool:
- """
- Check whether a URL is an absolute HTTP or HTTPS URL.
+ """Check whether a URL is an absolute HTTP or HTTPS URL.
:param url: URL to validate.
:return: Whether the URL uses HTTP or HTTPS and contains a hostname.