diff --git a/tuf/client_rework/metadata_wrapper.py b/tuf/client_rework/metadata_wrapper.py index 6f182dc336..18f0d6d9aa 100644 --- a/tuf/client_rework/metadata_wrapper.py +++ b/tuf/client_rework/metadata_wrapper.py @@ -9,7 +9,7 @@ from securesystemslib.keys import format_metadata_to_key -import tuf.exceptions +from tuf import exceptions, formats from tuf.api import metadata @@ -64,7 +64,7 @@ def verify(self, keys, threshold): verified += 1 if verified < threshold: - raise tuf.exceptions.InsufficientKeysError + raise exceptions.InsufficientKeysError def persist(self, filename): """ @@ -77,13 +77,13 @@ def expires(self, reference_time=None): TODO """ if reference_time is None: - expires_timestamp = tuf.formats.datetime_to_unix_timestamp( + expires_timestamp = formats.datetime_to_unix_timestamp( self._meta.signed.expires ) reference_time = int(time.time()) if expires_timestamp < reference_time: - raise tuf.exceptions.ExpiredMetadataError + raise exceptions.ExpiredMetadataError class RootWrapper(MetadataWrapper): diff --git a/tuf/client_rework/mirrors_download.py b/tuf/client_rework/mirrors_download.py index 996b8a0b0a..03f6006795 100644 --- a/tuf/client_rework/mirrors_download.py +++ b/tuf/client_rework/mirrors_download.py @@ -44,7 +44,7 @@ from securesystemslib import exceptions, util import tuf -import tuf.formats +from tuf import formats from tuf.requests_fetcher import RequestsFetcher # See 'log.py' to learn how logging is handled in TUF. @@ -61,7 +61,7 @@ class Mirrors: def __init__( self, mirrors_dict: Dict, fetcher: Optional["FetcherInterface"] = None ): - tuf.formats.MIRRORDICT_SCHEMA.check_match(mirrors_dict) + formats.MIRRORDICT_SCHEMA.check_match(mirrors_dict) self._config = mirrors_dict if fetcher is None: @@ -97,7 +97,7 @@ def _get_list_of_mirrors(self, file_type, file_path): """ # Checking if all the arguments have appropriate format. - tuf.formats.RELPATH_SCHEMA.check_match(file_path) + formats.RELPATH_SCHEMA.check_match(file_path) securesystemslib.formats.NAME_SCHEMA.check_match(file_type) # Verify 'file_type' is supported. @@ -243,7 +243,7 @@ def _download_file(self, url, required_length, strict_required_length=True): # Raise 'securesystemslib.exceptions.FormatError' if there is # a mismatch. securesystemslib.formats.URL_SCHEMA.check_match(url) - tuf.formats.LENGTH_SCHEMA.check_match(required_length) + formats.LENGTH_SCHEMA.check_match(required_length) # 'url.replace('\\', '/')' is needed for compatibility with # Windows-based systems, because they might use back-slashes in place diff --git a/tuf/client_rework/requests_fetcher.py b/tuf/client_rework/requests_fetcher.py index bdd52fec44..9c9631b48d 100644 --- a/tuf/client_rework/requests_fetcher.py +++ b/tuf/client_rework/requests_fetcher.py @@ -11,10 +11,9 @@ # Imports import requests import six -import urllib3.exceptions +import urllib3.exceptions as urllib3_ex -import tuf.exceptions -import tuf.settings +from tuf import exceptions, settings from tuf.client_rework.fetcher import FetcherInterface # Globals @@ -58,9 +57,9 @@ def fetch(self, url, required_length): bytes. Raises: - tuf.exceptions.SlowRetrievalError: A timeout occurs while receiving + exceptions.SlowRetrievalError: A timeout occurs while receiving data. - tuf.exceptions.FetcherHTTPError: An HTTP error code is received. + exceptions.FetcherHTTPError: An HTTP error code is received. Returns: A bytes iterator @@ -84,7 +83,7 @@ def fetch(self, url, required_length): except requests.HTTPError as e: response.close() status = e.response.status_code - raise tuf.exceptions.FetcherHTTPError(str(e), status) + raise exceptions.FetcherHTTPError(str(e), status) # Define a generator function to be returned by fetch. This way the # caller of fetch can differentiate between connection and actual data @@ -130,8 +129,8 @@ def chunks(): if bytes_received >= required_length: break - except urllib3.exceptions.ReadTimeoutError as e: - raise tuf.exceptions.SlowRetrievalError(str(e)) + except urllib3_ex.ReadTimeoutError as e: + raise exceptions.SlowRetrievalError(str(e)) finally: response.close() @@ -147,7 +146,7 @@ def _get_session(self, url): parsed_url = six.moves.urllib.parse.urlparse(url) if not parsed_url.scheme or not parsed_url.hostname: - raise tuf.exceptions.URLParsingError( + raise exceptions.URLParsingError( "Could not get scheme and hostname from URL: " + url )