@@ -29,15 +29,15 @@ class FetcherInterface:
2929 __metaclass__ = abc .ABCMeta
3030
3131 @abc .abstractmethod
32- def fetch (self , url : str , required_length : int ) -> Iterator [bytes ]:
32+ def fetch (self , url : str , max_length : int ) -> Iterator [bytes ]:
3333 """Fetches the contents of HTTP/HTTPS url from a remote server.
3434
35- Ensures the length of the downloaded data is up to 'required_length '.
35+ Ensures the length of the downloaded data is up to 'max_length '.
3636
3737 Arguments:
3838 url: A URL string that represents a file location.
39- required_length : An integer value representing the file length in
40- bytes.
39+ max_length : An integer value representing the maximum
40+ number of bytes to be downloaded .
4141
4242 Raises:
4343 tuf.exceptions.SlowRetrievalError: A timeout occurs while receiving
@@ -50,21 +50,20 @@ def fetch(self, url: str, required_length: int) -> Iterator[bytes]:
5050 raise NotImplementedError # pragma: no cover
5151
5252 @contextmanager
53- def download_file (self , url : str , required_length : int ) -> Iterator [IO ]:
53+ def download_file (self , url : str , max_length : int ) -> Iterator [IO ]:
5454 """Opens a connection to 'url' and downloads the content
55- up to 'required_length '.
55+ up to 'max_length '.
5656
5757 Args:
5858 url: a URL string that represents the location of the file.
59- required_length : an integer value representing the length of
60- the file or an upper boundary .
59+ max_length : an integer value representing the length of
60+ the file or an upper bound .
6161
6262 Raises:
63- DownloadLengthMismatchError: a mismatch of observed vs expected
64- lengths while downloading the file.
63+ DownloadLengthMismatchError: downloaded bytes exceed 'max_length'.
6564
6665 Yields:
67- A file object that points to the contents of 'url'.
66+ A TemporaryFile object that points to the contents of 'url'.
6867 """
6968 # 'url.replace('\\', '/')' is needed for compatibility with
7069 # Windows-based systems, because they might use back-slashes in place
@@ -78,21 +77,21 @@ def download_file(self, url: str, required_length: int) -> Iterator[IO]:
7877 number_of_bytes_received = 0
7978
8079 with tempfile .TemporaryFile () as temp_file :
81- chunks = self .fetch (url , required_length )
80+ chunks = self .fetch (url , max_length )
8281 for chunk in chunks :
8382 temp_file .write (chunk )
8483 number_of_bytes_received += len (chunk )
85- if number_of_bytes_received > required_length :
84+ if number_of_bytes_received > max_length :
8685 raise exceptions .DownloadLengthMismatchError (
87- required_length , number_of_bytes_received
86+ max_length , number_of_bytes_received
8887 )
8988 temp_file .seek (0 )
9089 yield temp_file
9190
92- def download_bytes (self , url : str , required_length : int ) -> bytes :
91+ def download_bytes (self , url : str , max_length : int ) -> bytes :
9392 """Download bytes from given url
9493
9594 Returns the downloaded bytes, otherwise like download_file()
9695 """
97- with self .download_file (url , required_length ) as dl_file :
96+ with self .download_file (url , max_length ) as dl_file :
9897 return dl_file .read ()
0 commit comments