From 8b6326f070c941510ebf1d27e53f501610406ea4 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Fri, 13 Nov 2026 20:23:13 +0100 Subject: refactor(core): replace HTTP status magic numbers Use `HTTPStatus` constants for standard response codes and a named upper bound for retryable server errors so network and task status handling is self-documenting. --- webmentions_ssg/net.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'webmentions_ssg/net.py') diff --git a/webmentions_ssg/net.py b/webmentions_ssg/net.py index 0314810..7c29edc 100644 --- a/webmentions_ssg/net.py +++ b/webmentions_ssg/net.py @@ -9,6 +9,7 @@ import socket import time from collections.abc import Iterable from contextlib import ExitStack +from http import HTTPStatus from urllib.parse import urlsplit import dns.exception @@ -20,6 +21,7 @@ from httpcore._backends.sync import SyncStream NAT64_PREFIX = ipaddress.IPv6Network("64:ff9b::/96") IPV4_COMPATIBLE_PREFIX = ipaddress.IPv6Network("::/96") +NETWORK_CONNECT_TIMOUT_ERROR = 599 class AddressResolutionError(Exception): @@ -285,4 +287,12 @@ def read_limited_body(response: httpx.Response, max_bytes: int, *, label: str) - def is_temporary_status(status: int) -> bool: """Return whether an HTTP status is normally retryable.""" - return status in {408, 425, 429} or 500 <= status <= 599 + return ( + status + in { + HTTPStatus.REQUEST_TIMEOUT, + HTTPStatus.TOO_EARLY, + HTTPStatus.TOO_MANY_REQUESTS, + } + or HTTPStatus.INTERNAL_SERVER_ERROR <= status <= NETWORK_CONNECT_TIMOUT_ERROR + ) -- cgit v1.3.1