mirror of
https://github.com/kernelkit/infix.git
synced 2026-07-22 01:13:00 +02:00
test: allow silencing curl connection failures on retry
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
+4
-2
@@ -99,12 +99,13 @@ def warn(msg):
|
||||
RST = "\033[0m"
|
||||
print(f"{YELLOW}warn - {msg}{RST}")
|
||||
|
||||
def curl(url, timeout=10):
|
||||
def curl(url, timeout=10, silent=False):
|
||||
"""Fetch a URL and return its response body as a UTF-8 string.
|
||||
|
||||
Args:
|
||||
url (str): The full URL to fetch.
|
||||
timeout (int): Request timeout in seconds.
|
||||
silent (bool): If True, suppress warning on failure (for retry scenarios).
|
||||
|
||||
Returns:
|
||||
str | None: Response body as text, or None if the request failed.
|
||||
@@ -115,5 +116,6 @@ def curl(url, timeout=10):
|
||||
with urllib.request.urlopen(url, timeout=timeout) as response:
|
||||
return response.read().decode('utf-8', errors='replace')
|
||||
except (urllib.error.URLError, ConnectionResetError, UnicodeEncodeError) as e:
|
||||
print(f"[WARN] curl: failed to fetch {url}: {e}")
|
||||
if not silent:
|
||||
print(f"[WARN] curl: failed to fetch {url}: {e}")
|
||||
return ""
|
||||
Reference in New Issue
Block a user