1919from lib .core .serviceproviders import BaseAnnotationService
2020from lib .infrastructure .stream_data_handler import StreamedAnnotations
2121from pydantic import parse_obj_as
22+ from superannotate .lib .infrastructure .services .http_client import AIOHttpSession
2223
2324logger = logging .getLogger ("sa" )
2425
2526
2627class AnnotationService (BaseAnnotationService ):
27- ASSETS_PROVIDER_VERSION = "v2 .01"
28+ ASSETS_PROVIDER_VERSION = "v3 .01"
2829 DEFAULT_CHUNK_SIZE = 5000
2930
3031 URL_GET_ANNOTATIONS = "items/annotations/download"
@@ -71,13 +72,12 @@ async def _sync_large_annotation(self, team_id, project_id, item_id):
7172 self .assets_provider_url ,
7273 self .URL_START_FILE_SYNC .format (item_id = item_id ),
7374 )
74- async with aiohttp . ClientSession (
75+ async with AIOHttpSession (
7576 connector = aiohttp .TCPConnector (ssl = False ),
7677 headers = self .client .default_headers ,
77- raise_for_status = True ,
7878 ) as session :
79- await session .post ( sync_url , params = sync_params )
80-
79+ _response = await session .request ( "post" , sync_url , params = sync_params )
80+ _response . raise_for_status ()
8181 sync_params .pop ("current_source" )
8282 sync_params .pop ("desired_source" )
8383
@@ -115,12 +115,12 @@ async def get_big_annotation(
115115 team_id = project .team_id , project_id = project .id , item_id = item .id
116116 )
117117
118- async with aiohttp . ClientSession (
118+ async with AIOHttpSession (
119119 connector = aiohttp .TCPConnector (ssl = False ),
120120 headers = self .client .default_headers ,
121- raise_for_status = True ,
122121 ) as session :
123- start_response = await session .post (url , params = query_params )
122+ start_response = await session .request ("post" , url , params = query_params )
123+ start_response .raise_for_status ()
124124 large_annotation = await start_response .json ()
125125
126126 reporter .update_progress ()
@@ -198,12 +198,12 @@ async def download_big_annotation(
198198 team_id = project .team_id , project_id = project .id , item_id = item_id
199199 )
200200
201- async with aiohttp . ClientSession (
201+ async with AIOHttpSession (
202202 connector = aiohttp .TCPConnector (ssl = False ),
203203 headers = self .client .default_headers ,
204- raise_for_status = True ,
205204 ) as session :
206- start_response = await session .post (url , params = query_params )
205+ start_response = await session .request ("post" , url , params = query_params )
206+ start_response .raise_for_status ()
207207 res = await start_response .json ()
208208 Path (download_path ).mkdir (exist_ok = True , parents = True )
209209
@@ -257,10 +257,9 @@ async def upload_small_annotations(
257257
258258 headers = copy .copy (self .client .default_headers )
259259 del headers ["Content-Type" ]
260- async with aiohttp . ClientSession (
260+ async with AIOHttpSession (
261261 headers = headers ,
262262 connector = aiohttp .TCPConnector (ssl = False ),
263- raise_for_status = True ,
264263 ) as session :
265264 data = aiohttp .FormData (quote_fields = False )
266265 for key , file in items_name_file_map .items ():
@@ -272,15 +271,12 @@ async def upload_small_annotations(
272271 content_type = "application/json" ,
273272 )
274273
275- _response = await session .post (
276- url ,
277- params = {
278- "team_id" : project .team_id ,
279- "project_id" : project .id ,
280- "folder_id" : folder .id ,
281- },
282- data = data ,
283- )
274+ params = {
275+ "team_id" : project .team_id ,
276+ "project_id" : project .id ,
277+ "folder_id" : folder .id ,
278+ }
279+ _response = await session .request ("post" , url , params = params , data = data )
284280 if not _response .ok :
285281 logger .debug (f"Status code { str (_response .status )} " )
286282 logger .debug (await _response .text ())
@@ -301,23 +297,20 @@ async def upload_big_annotation(
301297 data : io .StringIO ,
302298 chunk_size : int ,
303299 ) -> bool :
304- async with aiohttp . ClientSession (
300+ async with AIOHttpSession (
305301 connector = aiohttp .TCPConnector (ssl = False ),
306302 headers = self .client .default_headers ,
307- raise_for_status = True ,
308303 ) as session :
309304 params = {
310305 "team_id" : project .team_id ,
311306 "project_id" : project .id ,
312307 "folder_id" : folder .id ,
313308 }
314- start_response = await session .post (
315- urljoin (
316- self .assets_provider_url ,
317- self .URL_START_FILE_UPLOAD_PROCESS .format (item_id = item_id ),
318- ),
319- params = params ,
309+ url = urljoin (
310+ self .assets_provider_url ,
311+ self .URL_START_FILE_UPLOAD_PROCESS .format (item_id = item_id ),
320312 )
313+ start_response = await session .request ("post" , url , params = params )
321314 if not start_response .ok :
322315 raise AppException (str (await start_response .text ()))
323316 process_info = await start_response .json ()
0 commit comments