Fetcher¶
Provides an interface for network IO abstraction.
- class tuf.ngclient.fetcher.FetcherInterface¶
Bases:
objectDefines an interface for abstract network download.
By providing a concrete implementation of the abstract interface, users of the framework can plug-in their preferred/customized network stack.
- download_bytes(url: str, max_length: int) bytes¶
Download bytes from given url
Returns the downloaded bytes, otherwise like download_file()
- download_file(url: str, max_length: int) Iterator[IO]¶
Opens a connection to ‘url’ and downloads the content up to ‘max_length’.
- Parameters
url – a URL string that represents the location of the file.
max_length – an integer value representing the length of the file or an upper bound.
- Raises
DownloadLengthMismatchError – downloaded bytes exceed ‘max_length’.
- Yields
A TemporaryFile object that points to the contents of ‘url’.
- abstract fetch(url: str, max_length: int) Iterator[bytes]¶
Fetches the contents of HTTP/HTTPS url from a remote server.
Ensures the length of the downloaded data is up to ‘max_length’.
- Parameters
url – A URL string that represents a file location.
max_length – An integer value representing the maximum number of bytes to be downloaded.
- Raises
tuf.exceptions.SlowRetrievalError – A timeout occurs while receiving data.
tuf.exceptions.FetcherHTTPError – An HTTP error code is received.
- Returns
A bytes iterator