From c7993952c585b66acad5275e39dbf91cf662b975 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Thu, 12 Nov 2026 22:07:12 +0100 Subject: 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. --- webmentions_ssg/net.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'webmentions_ssg/net.py') 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. -- cgit v1.3.1