66from urllib .parse import urlparse
77
88from gen3 .utils import append_query_params , DEFAULT_BACKOFF_SETTINGS
9- from gen3 .auth import Gen3CurlError , check_curl_status
109
1110
1211def wsurl_to_tokens (ws_urlstr ):
@@ -20,23 +19,23 @@ def wsurl_to_tokens(ws_urlstr):
2019 raise Exception ("invalid path {}" .format (ws_urlstr ))
2120 return (pathparts [0 ], "/" .join (pathparts [1 :]))
2221
23- @backoff .on_exception (backoff .expo , Gen3CurlError , ** DEFAULT_BACKOFF_SETTINGS )
22+ @backoff .on_exception (backoff .expo , requests . HTTPError , ** DEFAULT_BACKOFF_SETTINGS )
2423def get_url (urlstr , dest_path ):
2524 """Simple url fetch to dest_path with backoff"""
2625 res = requests .get (urlstr )
27- check_curl_status ( res )
26+ res . raise_for_status ( )
2827 if dest_path == "-" :
2928 sys .stdout .write (res .text )
3029 else :
3130 with open (dest_path , 'wb' ) as f :
3231 f .write (res .content )
3332
34- @backoff .on_exception (backoff .expo , Gen3CurlError , ** DEFAULT_BACKOFF_SETTINGS )
33+ @backoff .on_exception (backoff .expo , requests . HTTPError , ** DEFAULT_BACKOFF_SETTINGS )
3534def put_url (urlstr , src_path ):
3635 """Simple put src_path to url with backoff"""
3736 with open (src_path , 'rb' ) as f :
3837 res = requests .put (urlstr , data = f )
39- check_curl_status ( res )
38+ res . raise_for_status ( )
4039
4140
4241class Gen3WsStorage :
@@ -63,7 +62,7 @@ def __init__(
6362 """
6463 self ._auth_provider = auth_provider
6564
66- @backoff .on_exception (backoff .expo , Gen3CurlError , ** DEFAULT_BACKOFF_SETTINGS )
65+ @backoff .on_exception (backoff .expo , requests . HTTPError , ** DEFAULT_BACKOFF_SETTINGS )
6766 def upload_url (self , ws , wskey ):
6867 """
6968 Get a upload url for the given workspace key
@@ -74,19 +73,19 @@ def upload_url(self, ws, wskey):
7473 """
7574 wskey = wskey .lstrip ("/" )
7675 res = self ._auth_provider .curl ("/ws-storage/upload/{}/{}" .format (ws , wskey ))
77- check_curl_status ( res )
76+ res . raise_for_status ( )
7877 return res .json ()
7978
8079
81- @backoff .on_exception (backoff .expo , Gen3CurlError , ** DEFAULT_BACKOFF_SETTINGS )
80+ @backoff .on_exception (backoff .expo , requests . HTTPError , ** DEFAULT_BACKOFF_SETTINGS )
8281 def upload (self , src_path , dest_ws , dest_wskey ):
8382 """
8483 Upload a local file to the specified workspace path
8584 """
8685 url = self .upload_url (dest_ws , dest_wskey )["Data" ]
8786 put_url (url , src_path )
8887
89- @backoff .on_exception (backoff .expo , Gen3CurlError , ** DEFAULT_BACKOFF_SETTINGS )
88+ @backoff .on_exception (backoff .expo , requests . HTTPError , ** DEFAULT_BACKOFF_SETTINGS )
9089 def download_url (self , ws , wskey ):
9190 """
9291 Get a download url for the given workspace key
@@ -97,7 +96,7 @@ def download_url(self, ws, wskey):
9796 """
9897 wskey = wskey .lstrip ("/" )
9998 res = self ._auth_provider .curl ("/ws-storage/download/{}/{}" .format (ws , wskey ))
100- check_curl_status ( res )
99+ res . raise_for_status ( )
101100 return res .json ()
102101
103102
@@ -128,7 +127,7 @@ def copy(self, src_urlstr, dest_urlstr):
128127 return self .upload (src_urlstr , pathparts [0 ], pathparts [1 ])
129128 raise Exception ("source and destination may not both be local" )
130129
131- @backoff .on_exception (backoff .expo , Gen3CurlError , ** DEFAULT_BACKOFF_SETTINGS )
130+ @backoff .on_exception (backoff .expo , requests . HTTPError , ** DEFAULT_BACKOFF_SETTINGS )
132131 def ls (self , ws , wskey ):
133132 """
134133 List the contents under the given workspace path
@@ -139,7 +138,7 @@ def ls(self, ws, wskey):
139138 """
140139 wskey = wskey .lstrip ("/" )
141140 res = self ._auth_provider .curl ("/ws-storage/list/{}/{}" .format (ws , wskey ))
142- check_curl_status ( res )
141+ res . raise_for_status ( )
143142 return res .json ()
144143
145144
@@ -155,7 +154,7 @@ def ls_path(self, ws_urlstr):
155154 pathparts = wsurl_to_tokens (ws_urlstr )
156155 return self .ls (pathparts [0 ], pathparts [1 ])
157156
158- @backoff .on_exception (backoff .expo , Gen3CurlError , ** DEFAULT_BACKOFF_SETTINGS )
157+ @backoff .on_exception (backoff .expo , requests . HTTPError , ** DEFAULT_BACKOFF_SETTINGS )
159158 def rm (self , ws , wskey ):
160159 """
161160 Remove the given workspace key
@@ -166,7 +165,7 @@ def rm(self, ws, wskey):
166165 """
167166 wskey = wskey .lstrip ("/" )
168167 res = self ._auth_provider .curl ("/ws-storage/list/{}/{}" .format (ws , wskey ), request = "DELETE" )
169- check_curl_status ( res )
168+ res . raise_for_status ( )
170169 return res .json ()
171170
172171 def rm_path (self , ws_urlstr ):
0 commit comments