@@ -139,9 +139,7 @@ async def is_alive(self, *, timeout: float | None = None) -> IsAliveResponse:
139139 session = await self ._ensure_session ()
140140 timeout_value = self ._get_timeout (timeout )
141141 async with session .get (
142- f"{ self ._api_url } /is_alive" ,
143- headers = self ._headers ,
144- timeout = aiohttp .ClientTimeout (total = timeout_value )
142+ f"{ self ._api_url } /is_alive" , headers = self ._headers , timeout = aiohttp .ClientTimeout (total = timeout_value )
145143 ) as response :
146144 if response .status == 200 :
147145 data = await response .json ()
@@ -150,12 +148,9 @@ async def is_alive(self, *, timeout: float | None = None) -> IsAliveResponse:
150148 data = await response .json ()
151149 exc_transfer = _ExceptionTransfer (** data ["swerexception" ])
152150 self ._handle_transfer_exception (exc_transfer )
153-
151+
154152 data = await response .json ()
155- msg = (
156- f"Status code { response .status } from { self ._api_url } /is_alive. "
157- f"Message: { data .get ('detail' )} "
158- )
153+ msg = f"Status code { response .status } from { self ._api_url } /is_alive. Message: { data .get ('detail' )} "
159154 return IsAliveResponse (is_alive = False , message = msg )
160155 except aiohttp .ClientError :
161156 msg = f"Failed to connect to { self ._config .host } \n "
@@ -172,11 +167,9 @@ async def wait_until_alive(self, *, timeout: float = 60.0):
172167 async def _request (self , endpoint : str , request : BaseModel | None , output_class : Any ):
173168 """Small helper to make requests to the server and handle errors and output."""
174169 session = await self ._ensure_session ()
175-
170+
176171 async with session .post (
177- f"{ self ._api_url } /{ endpoint } " ,
178- json = request .model_dump () if request else None ,
179- headers = self ._headers
172+ f"{ self ._api_url } /{ endpoint } " , json = request .model_dump () if request else None , headers = self ._headers
180173 ) as response :
181174 await self ._handle_response_errors (response )
182175 data = await response .json ()
@@ -210,46 +203,33 @@ async def upload(self, request: UploadRequest) -> UploadResponse:
210203 """Uploads a file"""
211204 source = Path (request .source_path ).resolve ()
212205 self .logger .debug ("Uploading file from %s to %s" , request .source_path , request .target_path )
213-
206+
214207 session = await self ._ensure_session ()
215-
208+
216209 if source .is_dir ():
217210 # Ignore cleanup errors: See https://github.com/SWE-agent/SWE-agent/issues/1005
218211 with tempfile .TemporaryDirectory (ignore_cleanup_errors = True ) as temp_dir :
219212 zip_path = Path (temp_dir ) / "zipped_transfer.zip"
220213 shutil .make_archive (str (zip_path .with_suffix ("" )), "zip" , source )
221214 self .logger .debug ("Created zip file at %s" , zip_path )
222-
215+
223216 data = aiohttp .FormData ()
224- data .add_field ('file' ,
225- open (zip_path , 'rb' ),
226- filename = zip_path .name ,
227- content_type = 'application/zip' )
228- data .add_field ('target_path' , request .target_path )
229- data .add_field ('unzip' , 'true' )
230-
231- async with session .post (
232- f"{ self ._api_url } /upload" ,
233- data = data ,
234- headers = self ._headers
235- ) as response :
217+ data .add_field ("file" , open (zip_path , "rb" ), filename = zip_path .name , content_type = "application/zip" )
218+ data .add_field ("target_path" , request .target_path )
219+ data .add_field ("unzip" , "true" )
220+
221+ async with session .post (f"{ self ._api_url } /upload" , data = data , headers = self ._headers ) as response :
236222 await self ._handle_response_errors (response )
237223 return UploadResponse (** (await response .json ()))
238224 elif source .is_file ():
239225 self .logger .debug ("Uploading file from %s to %s" , source , request .target_path )
240-
226+
241227 data = aiohttp .FormData ()
242- data .add_field ('file' ,
243- open (source , 'rb' ),
244- filename = source .name )
245- data .add_field ('target_path' , request .target_path )
246- data .add_field ('unzip' , 'false' )
247-
248- async with session .post (
249- f"{ self ._api_url } /upload" ,
250- data = data ,
251- headers = self ._headers
252- ) as response :
228+ data .add_field ("file" , open (source , "rb" ), filename = source .name )
229+ data .add_field ("target_path" , request .target_path )
230+ data .add_field ("unzip" , "false" )
231+
232+ async with session .post (f"{ self ._api_url } /upload" , data = data , headers = self ._headers ) as response :
253233 await self ._handle_response_errors (response )
254234 return UploadResponse (** (await response .json ()))
255235 else :
0 commit comments