From 7bb916f96201792bcc56983463be1733917795be Mon Sep 17 00:00:00 2001 From: Martin Vrachev Date: Wed, 19 Jan 2022 20:24:02 +0200 Subject: [PATCH] Document DownloadError for RequestsFetcher.fetch() We should document that "DownloadError" is thrown inside RequestsFetcher.fetch(). Signed-off-by: Martin Vrachev --- tuf/ngclient/_internal/requests_fetcher.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tuf/ngclient/_internal/requests_fetcher.py b/tuf/ngclient/_internal/requests_fetcher.py index 9587898b..03b9ed1c 100644 --- a/tuf/ngclient/_internal/requests_fetcher.py +++ b/tuf/ngclient/_internal/requests_fetcher.py @@ -61,6 +61,7 @@ def fetch(self, url: str) -> Iterator[bytes]: exceptions.SlowRetrievalError: A timeout occurs while receiving data. exceptions.FetcherHTTPError: An HTTP error code is received. + exceptions.DownloadError: When there is a problem parsing the url. Returns: A bytes iterator @@ -126,13 +127,16 @@ def _chunks(self, response: "requests.Response") -> Iterator[bytes]: def _get_session(self, url: str) -> requests.Session: """Returns a different customized requests.Session per schema+hostname combination. + + Raises: + exceptions.DownloadError: When there is a problem parsing the url. """ # Use a different requests.Session per schema+hostname combination, to # reuse connections while minimizing subtle security issues. parsed_url = parse.urlparse(url) if not parsed_url.scheme or not parsed_url.hostname: - raise exceptions.DownloadError("Failed to parse URL") + raise exceptions.DownloadError("Failed to parse URL {url}") session_index = parsed_url.scheme + "+" + parsed_url.hostname session = self._sessions.get(session_index)