aboutsummaryrefslogtreecommitdiff
path: root/webmentions_ssg/net.py
diff options
context:
space:
mode:
authorDennis Fink2026-11-13 20:23:13 +0100
committerDennis Fink2026-11-13 20:23:13 +0100
commit8b6326f070c941510ebf1d27e53f501610406ea4 (patch)
tree1db02dbc58207e3ef557e8a6f6d7020363ef3c7b /webmentions_ssg/net.py
parent1f784f2b87ed0b2fd478e46d0d292c33f3150a3b (diff)
downloadwebmentions-ssg-8b6326f070c941510ebf1d27e53f501610406ea4.tar.gz
webmentions-ssg-8b6326f070c941510ebf1d27e53f501610406ea4.zip
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.
Diffstat (limited to '')
-rw-r--r--webmentions_ssg/net.py12
1 files changed, 11 insertions, 1 deletions
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
+ )