@@ -95,6 +95,23 @@ def verify_checksum(self, artifact: SolcArtifact, file_handle: BufferedRandom) -
9595 if artifact .checksum_keccak256 and artifact .checksum_keccak256 != local_keccak256 :
9696 raise ChecksumMismatchError (artifact .checksum_keccak256 , local_keccak256 , "Keccak256" )
9797
98+ def _download_artifact (self , artifact : SolcArtifact ) -> None :
99+ """Download artifact and verify checksums."""
100+ response = self .session .get (artifact .download_url , stream = True )
101+ response .raise_for_status ()
102+
103+ with open (artifact .file_path , "w+b" , opener = partial (os .open , mode = 0o664 )) as f :
104+ try :
105+ for chunk in response .iter_content (chunk_size = 8192 ):
106+ if chunk :
107+ f .write (chunk )
108+ except KeyboardInterrupt :
109+ if artifact .file_path .exists ():
110+ artifact .file_path .unlink (missing_ok = True )
111+ raise
112+
113+ self .verify_checksum (artifact , f )
114+
98115 def download_and_install (self , version : SolcVersion , silent : bool = False ) -> bool :
99116 """Download and install a Solidity compiler version."""
100117 if self .filesystem .is_installed (version ):
@@ -115,21 +132,7 @@ def download_and_install(self, version: SolcVersion, silent: bool = False) -> bo
115132 self .filesystem .ensure_artifact_directory (version )
116133
117134 try :
118- response = self .session .get (artifact .download_url , stream = True )
119- response .raise_for_status ()
120-
121- with open (artifact .file_path , "w+b" , opener = partial (os .open , mode = 0o664 )) as f :
122- try :
123- for chunk in response .iter_content (chunk_size = 8192 ):
124- if chunk :
125- f .write (chunk )
126- except KeyboardInterrupt :
127- # Clean up partially downloaded file on interrupt
128- if artifact .file_path .exists ():
129- artifact .file_path .unlink (missing_ok = True )
130- raise
131-
132- self .verify_checksum (artifact , f )
135+ self ._download_artifact (artifact )
133136
134137 if artifact .is_zip_archive :
135138 self ._extract_zip_archive (artifact )
0 commit comments