mirror of
https://github.com/pyenv/pyenv.git
synced 2026-09-10 15:46:17 -04:00
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 <noreply@anthropic.com>
This commit is contained in:
parent
bdf8d254fe
commit
4e2d2cdabd
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue