Skip to content

Commit 32011a7

Browse files
committed
Fix client imports
Fix imports to be vendoring compatible. Signed-off-by: Teodora Sechkova <[email protected]>
1 parent deee5b2 commit 32011a7

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

tuf/client_rework/metadata_wrapper.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from securesystemslib.keys import format_metadata_to_key
1111

12-
import tuf.exceptions
12+
from tuf import exceptions, formats
1313
from tuf.api import metadata
1414

1515

@@ -64,7 +64,7 @@ def verify(self, keys, threshold):
6464
verified += 1
6565

6666
if verified < threshold:
67-
raise tuf.exceptions.InsufficientKeysError
67+
raise exceptions.InsufficientKeysError
6868

6969
def persist(self, filename):
7070
"""
@@ -77,13 +77,13 @@ def expires(self, reference_time=None):
7777
TODO
7878
"""
7979
if reference_time is None:
80-
expires_timestamp = tuf.formats.datetime_to_unix_timestamp(
80+
expires_timestamp = formats.datetime_to_unix_timestamp(
8181
self._meta.signed.expires
8282
)
8383
reference_time = int(time.time())
8484

8585
if expires_timestamp < reference_time:
86-
raise tuf.exceptions.ExpiredMetadataError
86+
raise exceptions.ExpiredMetadataError
8787

8888

8989
class RootWrapper(MetadataWrapper):

tuf/client_rework/mirrors_download.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
from securesystemslib import exceptions, util
4545

4646
import tuf
47-
import tuf.formats
47+
from tuf import formats
4848
from tuf.requests_fetcher import RequestsFetcher
4949

5050
# See 'log.py' to learn how logging is handled in TUF.
@@ -61,7 +61,7 @@ class Mirrors:
6161
def __init__(
6262
self, mirrors_dict: Dict, fetcher: Optional["FetcherInterface"] = None
6363
):
64-
tuf.formats.MIRRORDICT_SCHEMA.check_match(mirrors_dict)
64+
formats.MIRRORDICT_SCHEMA.check_match(mirrors_dict)
6565
self._config = mirrors_dict
6666

6767
if fetcher is None:
@@ -97,7 +97,7 @@ def _get_list_of_mirrors(self, file_type, file_path):
9797
"""
9898

9999
# Checking if all the arguments have appropriate format.
100-
tuf.formats.RELPATH_SCHEMA.check_match(file_path)
100+
formats.RELPATH_SCHEMA.check_match(file_path)
101101
securesystemslib.formats.NAME_SCHEMA.check_match(file_type)
102102

103103
# Verify 'file_type' is supported.
@@ -243,7 +243,7 @@ def _download_file(self, url, required_length, strict_required_length=True):
243243
# Raise 'securesystemslib.exceptions.FormatError' if there is
244244
# a mismatch.
245245
securesystemslib.formats.URL_SCHEMA.check_match(url)
246-
tuf.formats.LENGTH_SCHEMA.check_match(required_length)
246+
formats.LENGTH_SCHEMA.check_match(required_length)
247247

248248
# 'url.replace('\\', '/')' is needed for compatibility with
249249
# Windows-based systems, because they might use back-slashes in place

tuf/client_rework/requests_fetcher.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
# Imports
1212
import requests
1313
import six
14-
import urllib3.exceptions
14+
import urllib3.exceptions as urllib3_ex
1515

16-
import tuf.exceptions
17-
import tuf.settings
16+
import tuf
17+
from tuf import exceptions, settings
1818
from tuf.client_rework.fetcher import FetcherInterface
1919

2020
# Globals
@@ -58,9 +58,9 @@ def fetch(self, url, required_length):
5858
bytes.
5959
6060
Raises:
61-
tuf.exceptions.SlowRetrievalError: A timeout occurs while receiving
61+
exceptions.SlowRetrievalError: A timeout occurs while receiving
6262
data.
63-
tuf.exceptions.FetcherHTTPError: An HTTP error code is received.
63+
exceptions.FetcherHTTPError: An HTTP error code is received.
6464
6565
Returns:
6666
A bytes iterator
@@ -76,15 +76,15 @@ def fetch(self, url, required_length):
7676
# - connect timeout (max delay before first byte is received)
7777
# - read (gap) timeout (max delay between bytes received)
7878
response = session.get(
79-
url, stream=True, timeout=tuf.settings.SOCKET_TIMEOUT
79+
url, stream=True, timeout=settings.SOCKET_TIMEOUT
8080
)
8181
# Check response status.
8282
try:
8383
response.raise_for_status()
8484
except requests.HTTPError as e:
8585
response.close()
8686
status = e.response.status_code
87-
raise tuf.exceptions.FetcherHTTPError(str(e), status)
87+
raise exceptions.FetcherHTTPError(str(e), status)
8888

8989
# Define a generator function to be returned by fetch. This way the
9090
# caller of fetch can differentiate between connection and actual data
@@ -99,11 +99,11 @@ def chunks():
9999
# large file in one shot. Before beginning the round, sleep
100100
# (if set) for a short amount of time so that the CPU is
101101
# not hogged in the while loop.
102-
if tuf.settings.SLEEP_BEFORE_ROUND:
103-
time.sleep(tuf.settings.SLEEP_BEFORE_ROUND)
102+
if settings.SLEEP_BEFORE_ROUND:
103+
time.sleep(settings.SLEEP_BEFORE_ROUND)
104104

105105
read_amount = min(
106-
tuf.settings.CHUNK_SIZE,
106+
settings.CHUNK_SIZE,
107107
required_length - bytes_received,
108108
)
109109

@@ -130,8 +130,8 @@ def chunks():
130130
if bytes_received >= required_length:
131131
break
132132

133-
except urllib3.exceptions.ReadTimeoutError as e:
134-
raise tuf.exceptions.SlowRetrievalError(str(e))
133+
except urllib3_ex.ReadTimeoutError as e:
134+
raise exceptions.SlowRetrievalError(str(e))
135135

136136
finally:
137137
response.close()
@@ -147,7 +147,7 @@ def _get_session(self, url):
147147
parsed_url = six.moves.urllib.parse.urlparse(url)
148148

149149
if not parsed_url.scheme or not parsed_url.hostname:
150-
raise tuf.exceptions.URLParsingError(
150+
raise exceptions.URLParsingError(
151151
"Could not get scheme and hostname from URL: " + url
152152
)
153153

0 commit comments

Comments
 (0)