From 4e2d2cdabdc0cfb61cbcc73bb01337b056270b96 Mon Sep 17 00:00:00 2001 From: anupamme Date: Tue, 4 Aug 2026 07:25:21 +0000 Subject: [PATCH] refactor: extract _fetch helper for requests calls in add_cpython.py Replaces the two repeated requests.get(url, timeout=30) call sites with a small _fetch() helper that centralises timeout and raise_for_status() logic. Also adds raise_for_status() to the shasum download call which previously had none, so HTTP errors surface clearly rather than failing downstream. Co-Authored-By: Claude Sonnet 4.6 --- plugins/python-build/scripts/add_cpython.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/plugins/python-build/scripts/add_cpython.py b/plugins/python-build/scripts/add_cpython.py index 3d9a3d1d..77c1dfe9 100755 --- a/plugins/python-build/scripts/add_cpython.py +++ b/plugins/python-build/scripts/add_cpython.py @@ -33,6 +33,13 @@ import tqdm logger = logging.getLogger(__name__) + +def _fetch(url: str) -> requests.Response: + response = requests.get(url, timeout=30) + response.raise_for_status() + return response + + CUTOFF_VERSION=packaging.version.Version('3.10') EXCLUDED_VERSIONS= { } @@ -542,8 +549,7 @@ class OpenSSLVersionsDirectory(KeyedList[_OpenSSLVersionInfo, packaging.version. url = "https://api.github.com/repos/openssl/openssl/releases" while url: - response = requests.get(url, timeout=30) - response.raise_for_status() + response = _fetch(url) matching = [ release for release in response.json() @@ -568,7 +574,7 @@ class OpenSSLVersionsDirectory(KeyedList[_OpenSSLVersionInfo, packaging.version. for asset in j_release['assets'] if urllib.parse.urlparse(asset['browser_download_url']).path.split('/')[-1].endswith('.sha256') ) - shasum_text = requests.get(shasum_url, timeout=30).text + shasum_text = _fetch(shasum_url).text shasum_data = jc.parse("hashsum", shasum_text, quiet=True)[0] package_hash, package_filename = shasum_data["hash"], shasum_data["filename"] del shasum_data, shasum_text, shasum_url