Skip to content

Commit

Permalink
Fix client imports
Browse files Browse the repository at this point in the history
Fix imports to be vendoring compatible.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
  • Loading branch information
sechkova committed Apr 8, 2021
1 parent deee5b2 commit 1b92b79
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
8 changes: 4 additions & 4 deletions tuf/client_rework/metadata_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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):
"""
Expand All @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions tuf/client_rework/mirrors_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
17 changes: 8 additions & 9 deletions tuf/client_rework/requests_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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
)

Expand Down

0 comments on commit 1b92b79

Please sign in to comment.