Fetcher

Provides an interface for network IO abstraction.

class tuf.ngclient.fetcher.FetcherInterface

Bases: object

Defines 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) Iterator[bytes]

Fetches the contents of HTTP/HTTPS url from a remote server.

Parameters

url – A URL string that represents a file location.

Raises
  • tuf.exceptions.SlowRetrievalError – A timeout occurs while receiving data.

  • tuf.exceptions.FetcherHTTPError – An HTTP error code is received.

Returns

A bytes iterator