@@ -115,65 +115,6 @@ def _get_access_info(obj_url: str, access_method: dict, headers: Optional[dict]
115115 return url , headers_as_dict
116116
117117
118- def _download_s3_file (s3_url : str , target_path : StrPath , headers : Optional [dict ] = None ) -> None :
119- """Download file from S3 URL directly using s3fs or requests (for signed URLs)."""
120- try :
121- # If the URL has query parameters (signed URL), use requests directly
122- if "?" in s3_url and ("X-Amz-Algorithm" in s3_url or "Signature" in s3_url ):
123- log .debug (f"Using requests for signed S3 URL" )
124- response = requests .get (s3_url , headers = headers or {}, timeout = DEFAULT_SOCKET_TIMEOUT , stream = True )
125- response .raise_for_status ()
126-
127- with open (target_path , "wb" ) as f :
128- for chunk in response .iter_content (chunk_size = CHUNK_SIZE ):
129- f .write (chunk )
130- return
131-
132- # For raw S3 URLs, try s3fs with different access patterns
133- log .debug (f"Using s3fs for S3 URL: { s3_url } " )
134- import s3fs
135-
136- s3_path = s3_url [5 :] # Remove 's3://' prefix
137-
138- # Try different S3 access methods in order of preference
139- access_methods = [
140- ("anonymous" , lambda : s3fs .S3FileSystem (anon = True )),
141- ("authenticated" , lambda : s3fs .S3FileSystem ()),
142- ("requester_pays" , lambda : s3fs .S3FileSystem (requester_pays = True )),
143- ]
144-
145- last_error = None
146- for method_name , fs_factory in access_methods :
147- try :
148- fs = fs_factory ()
149- with fs .open (s3_path , "rb" ) as s3_file :
150- with open (target_path , "wb" ) as local_file :
151- while True :
152- chunk = s3_file .read (CHUNK_SIZE )
153- if not chunk :
154- break
155- local_file .write (chunk )
156- log .debug (f"S3 download successful using { method_name } access" )
157- return
158- except Exception as e :
159- log .debug (f"S3 { method_name } access failed: { e } " )
160- last_error = e
161- continue
162-
163- # If all methods failed, raise the last error
164- if last_error :
165- raise last_error
166-
167- except ImportError as e :
168- raise ImportError ("s3fs package is required for S3 URL support" ) from e
169- except requests .exceptions .RequestException as e :
170- log .debug (f"S3 HTTP download failed: { e } " )
171- raise
172- except Exception as e :
173- log .debug (f"S3 download failed: { e } " )
174- raise
175-
176-
177118class CompactIdentifierResolver :
178119 _instance : Optional ["CompactIdentifierResolver" ] = None
179120 _initialized : bool = False
0 commit comments