@@ -1712,17 +1712,18 @@ def _get_file(self, filepath, verify_file_function, file_type, file_length,
1712
1712
file_mirror_errors = {}
1713
1713
file_object = None
1714
1714
1715
- if custom_download_handler is not None :
1716
- safe_download = custom_download_handler
1717
-
1718
- else :
1719
- safe_download = tuf .download .safe_download
1720
-
1721
1715
for file_mirror in file_mirrors :
1722
1716
try :
1723
- # Eensure the length of the downloaded file matches 'file_length'
1724
- # exactly.
1725
- file_object = safe_download (file_mirror , file_length )
1717
+ if custom_download_handler is not None :
1718
+ # When an external download handler is used, file length verification
1719
+ # is not expected. It is performed by verify_file_function()
1720
+ file_object = custom_download_handler (file_mirror )
1721
+
1722
+ else :
1723
+ # Ensure the length of the downloaded file matches 'file_length'
1724
+ # exactly even though it will be redundantly verified one more time
1725
+ # by verify_file_function().
1726
+ file_object = tuf .download .safe_download (file_mirror , file_length )
1726
1727
1727
1728
# Verify 'file_object' according to the callable function.
1728
1729
# 'file_object' is also verified if decompressed above (i.e., the
@@ -3252,33 +3253,21 @@ def download_target(self, target, destination_directory,
3252
3253
In order to comply with the TUF specification, the function implementation
3253
3254
should match the following description:
3254
3255
3255
- def download_handler_func(url, required_length )
3256
+ def download_handler_func(url)
3256
3257
<Purpose>
3257
- Given the 'url' and 'required_length' of the desired file, open a connection
3258
- to 'url', download it, and return the contents of the file. Also ensure
3259
- the length of the downloaded file matches 'required_length' exactly .
3258
+ Given the 'url' of the desired file,
3259
+ open a connection to 'url', download it, and return the contents
3260
+ of the file.
3260
3261
3261
3262
<Arguments>
3262
3263
url:
3263
3264
A URL string that represents the location of the file.
3264
3265
3265
- required_length:
3266
- An integer value representing the length of the file. This is an exact
3267
- limit.
3268
-
3269
3266
<Side Effects>
3270
3267
A temprorary file object is created to store the contents of 'url'.
3271
3268
3272
- <Exceptions>
3273
- DownloadLengthMismatchError, if there was a
3274
- mismatch of observed vs expected lengths while downloading the file.
3275
-
3276
- SlowRetrievalError, if the total downloaded was
3277
- done in less than the acceptable download speed (as set in
3278
- tuf.settings.py).
3279
-
3280
3269
<Returns>
3281
- A temporay file object that points to the contents of 'url'.
3270
+ A temporary file object that points to the contents of 'url'.
3282
3271
3283
3272
If None, tuf.download.safe_download is used.
3284
3273
0 commit comments