@@ -207,39 +207,19 @@ def post_data(self, file: Path) -> Dict[str, Any]:
207
207
208
208
def _upload (
209
209
self , session : requests .Session , url : str , dry_run : Optional [bool ] = False
210
- ) -> None :
211
- try :
212
- self ._do_upload (session , url , dry_run )
213
- except HTTPError as e :
214
- if (
215
- e .response .status_code == 400
216
- and "was ever registered" in e .response .text
217
- ):
218
- try :
219
- self ._register (session , url )
220
- except HTTPError as e :
221
- raise UploadError (e )
222
-
223
- raise UploadError (e )
224
-
225
- def _do_upload (
226
- self , session : requests .Session , url : str , dry_run : Optional [bool ] = False
227
210
) -> None :
228
211
for file in self .files :
229
212
# TODO: Check existence
230
213
231
- resp = self ._upload_file (session , url , file , dry_run )
232
-
233
- if not dry_run :
234
- resp .raise_for_status ()
214
+ self ._upload_file (session , url , file , dry_run )
235
215
236
216
def _upload_file (
237
217
self ,
238
218
session : requests .Session ,
239
219
url : str ,
240
220
file : Path ,
241
221
dry_run : Optional [bool ] = False ,
242
- ) -> requests . Response :
222
+ ) -> None :
243
223
from cleo .ui .progress_bar import ProgressBar
244
224
245
225
data = self .post_data (file )
@@ -290,6 +270,11 @@ def _upload_file(
290
270
"Redirects are not supported. "
291
271
"Is the URL missing a trailing slash?"
292
272
)
273
+ elif resp .status_code == 400 and "was ever registered" in resp .text :
274
+ self ._register (session , url )
275
+ resp .raise_for_status ()
276
+ else :
277
+ resp .raise_for_status ()
293
278
except (requests .ConnectionError , requests .HTTPError ) as e :
294
279
if self ._io .output .is_decorated ():
295
280
self ._io .overwrite (
@@ -299,8 +284,6 @@ def _upload_file(
299
284
finally :
300
285
self ._io .write_line ("" )
301
286
302
- return resp
303
-
304
287
def _register (self , session : requests .Session , url : str ) -> requests .Response :
305
288
"""
306
289
Register a package to a repository.
0 commit comments