@@ -1228,7 +1228,7 @@ def test_download_target_custom_download_handler(self):
1228
1228
download_filepath = os .path .join (destination_directory , target_filepath )
1229
1229
1230
1230
# Test passing a handler with correct signature but incorrect implementation
1231
- def test_1 (param_1 , param2 ):
1231
+ def test_1 (param_1 ):
1232
1232
pass
1233
1233
1234
1234
self .assertRaises (tuf .exceptions .NoWorkingMirrorError ,
@@ -1239,7 +1239,7 @@ def test_1(param_1, param2):
1239
1239
self .assertFalse (os .path .exists (download_filepath ))
1240
1240
1241
1241
# Test passing a handler with incorrect number of parameters
1242
- def test_2 (param_1 , param_2 , param_3 ):
1242
+ def test_2 (param_1 , param_2 ):
1243
1243
pass
1244
1244
1245
1245
with self .assertRaises (tuf .exceptions .NoWorkingMirrorError ) as cm :
@@ -1253,7 +1253,7 @@ def test_2(param_1, param_2, param_3):
1253
1253
self .assertFalse (os .path .exists (download_filepath ))
1254
1254
1255
1255
# Test passing a handler throwing an unexpected error
1256
- def test_3 (param_1 , param2 ):
1256
+ def test_3 (param_1 ):
1257
1257
raise IOError
1258
1258
1259
1259
with self .assertRaises (tuf .exceptions .NoWorkingMirrorError ) as cm :
@@ -1272,13 +1272,8 @@ def test_3(param_1, param2):
1272
1272
# Checks if the file has been successfully downloaded
1273
1273
self .assertTrue (os .path .exists (download_filepath ))
1274
1274
1275
- # Define a simple custom download handler mimicking
1276
- # the tuf.download call stack:
1277
- # safe_download()
1278
- # _download_file()
1279
- # _download_fixed_amount_of_data()
1280
- # _check_downloaded_length()
1281
- def download_handler (url , required_length ):
1275
+ # Define a simple custom download handler
1276
+ def download_handler (url ):
1282
1277
url = six .moves .urllib .parse .unquote (url ).replace ('\\ ' , '/' )
1283
1278
temp_file = tempfile .TemporaryFile ()
1284
1279
@@ -1287,32 +1282,12 @@ def download_handler(url, required_length):
1287
1282
with session .get (url , stream = True ,
1288
1283
timeout = tuf .settings .SOCKET_TIMEOUT ) as response :
1289
1284
1290
- # Check response status.
1285
+ # Check response status
1291
1286
response .raise_for_status ()
1292
1287
1293
- # Download fixed amount of data
1294
- average_download_speed = 0
1295
- number_of_bytes_received = 0
1296
-
1297
- start_time = timeit .default_timer ()
1298
-
1288
+ # Read the raw socket response
1299
1289
for chunk in response .iter_content (chunk_size = tuf .settings .CHUNK_SIZE ):
1300
- number_of_bytes_received += len (chunk )
1301
1290
temp_file .write (chunk )
1302
- if number_of_bytes_received >= required_length :
1303
- break
1304
-
1305
- stop_time = timeit .default_timer ()
1306
- average_download_speed = number_of_bytes_received / (stop_time - start_time )
1307
- if average_download_speed < tuf .settings .MIN_AVERAGE_DOWNLOAD_SPEED :
1308
- break
1309
-
1310
- #Check downloaded length
1311
- if number_of_bytes_received != required_length :
1312
- if average_download_speed < tuf .settings .MIN_AVERAGE_DOWNLOAD_SPEED :
1313
- raise tuf .exceptions .SlowRetrievalError (average_download_speed )
1314
-
1315
- raise tuf .exceptions .DownloadLengthMismatchError (required_length , number_of_bytes_received )
1316
1291
1317
1292
except Exception :
1318
1293
temp_file .close ()
@@ -1321,7 +1296,7 @@ def download_handler(url, required_length):
1321
1296
else :
1322
1297
return temp_file
1323
1298
1324
- #Test passing a custom download function
1299
+ # Test passing a custom download function
1325
1300
self .repository_updater .download_target (targetinfo , destination_directory ,
1326
1301
custom_download_handler = download_handler )
1327
1302
0 commit comments