11import argparse
22import contextlib
33import hashlib
4- import json
54import os
65import re
76import shutil
87import subprocess
98import sys
10- import urllib .request
119from pathlib import Path
1210from typing import Dict , List , Optional , Tuple
1311from zipfile import ZipFile
3028 WINDOWS_AMD64 ,
3129)
3230from .utils import (
31+ create_http_session ,
3332 get_arch ,
3433 mac_binary_is_native ,
3534 mac_binary_is_universal ,
@@ -242,7 +241,13 @@ def install_artifacts(versions: List[str], silent: bool = False) -> bool:
242241 Path .mkdir (artifact_file_dir , parents = True , exist_ok = True )
243242 if not silent :
244243 print (f"Installing solc '{ version } '..." )
245- urllib .request .urlretrieve (url , artifact_file_dir .joinpath (f"solc-{ version } " ))
244+ session = create_http_session ()
245+ response = session .get (url )
246+ response .raise_for_status ()
247+
248+ with open (artifact_file_dir .joinpath (f"solc-{ version } " ), "wb" ) as f :
249+ for chunk in response .iter_content (chunk_size = 8192 ):
250+ f .write (chunk )
246251
247252 verify_checksum (version )
248253
@@ -310,9 +315,10 @@ def verify_checksum(version: str) -> None:
310315
311316def get_soliditylang_checksums (version : str ) -> Tuple [str , Optional [str ]]:
312317 (_ , list_url ) = get_url (version = version )
313- # pylint: disable=consider-using-with
314- list_json = urllib .request .urlopen (list_url ).read ()
315- builds = json .loads (list_json )["builds" ]
318+ session = create_http_session ()
319+ response = session .get (list_url )
320+ response .raise_for_status ()
321+ builds = response .json ()["builds" ]
316322 matches = list (filter (lambda b : b ["version" ] == version , builds ))
317323
318324 if not matches or not matches [0 ]["sha256" ]:
@@ -414,21 +420,24 @@ def get_installable_versions() -> List[str]:
414420 return installable
415421
416422
417- # pylint: disable=consider-using-with
418423def get_available_versions () -> Dict [str , str ]:
424+ session = create_http_session ()
419425 (_ , list_url ) = get_url ()
420- list_json = urllib .request .urlopen (list_url ).read ()
421- available_releases = json .loads (list_json )["releases" ]
422- # pylint: disable=consider-using-with
426+ response = session .get (list_url )
427+ response .raise_for_status ()
428+ available_releases = response .json ()["releases" ]
429+
423430 if soliditylang_platform () == LINUX_AMD64 :
424431 (_ , list_url ) = get_url (version = EARLIEST_RELEASE [LINUX_AMD64 ])
425- github_json = urllib .request .urlopen (list_url ).read ()
426- additional_linux_versions = json .loads (github_json )["releases" ]
432+ response = session .get (list_url )
433+ response .raise_for_status ()
434+ additional_linux_versions = response .json ()["releases" ]
427435 available_releases .update (additional_linux_versions )
428436 elif sys .platform == "darwin" and get_arch () == "arm64" :
429437 # Fetch Alloy versions for ARM64 Darwin
430- alloy_json = urllib .request .urlopen (ALLOY_SOLC_JSON ).read ()
431- alloy_releases = json .loads (alloy_json )["releases" ]
438+ response = session .get (ALLOY_SOLC_JSON )
439+ response .raise_for_status ()
440+ alloy_releases = response .json ()["releases" ]
432441 # Filter to only include versions in the supported range (0.8.24+ are already universal)
433442 filtered_alloy_releases = {
434443 version : release
@@ -455,7 +464,9 @@ def soliditylang_platform() -> str:
455464
456465
457466def get_latest_release () -> str :
467+ session = create_http_session ()
458468 (_ , list_url ) = get_url ()
459- list_json = urllib .request .urlopen (list_url ).read ()
460- latest_release = json .loads (list_json )["latestRelease" ]
469+ response = session .get (list_url )
470+ response .raise_for_status ()
471+ latest_release = response .json ()["latestRelease" ]
461472 return latest_release
0 commit comments