Skip to content

Commit ad79f66

Browse files
committed
test: allow silencing curl connection failures on retry
Signed-off-by: Joachim Wiberg <[email protected]>
1 parent 4941b6f commit ad79f66

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

test/infamy/util.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,13 @@ def warn(msg):
9999
RST = "\033[0m"
100100
print(f"{YELLOW}warn - {msg}{RST}")
101101

102-
def curl(url, timeout=10):
102+
def curl(url, timeout=10, silent=False):
103103
"""Fetch a URL and return its response body as a UTF-8 string.
104104
105105
Args:
106106
url (str): The full URL to fetch.
107107
timeout (int): Request timeout in seconds.
108+
silent (bool): If True, suppress warning on failure (for retry scenarios).
108109
109110
Returns:
110111
str | None: Response body as text, or None if the request failed.
@@ -115,5 +116,6 @@ def curl(url, timeout=10):
115116
with urllib.request.urlopen(url, timeout=timeout) as response:
116117
return response.read().decode('utf-8', errors='replace')
117118
except (urllib.error.URLError, ConnectionResetError, UnicodeEncodeError) as e:
118-
print(f"[WARN] curl: failed to fetch {url}: {e}")
119+
if not silent:
120+
print(f"[WARN] curl: failed to fetch {url}: {e}")
119121
return ""

0 commit comments

Comments
 (0)