Skip to content

Commit b5c8ba0

Browse files
authored
Merge pull request #1261 from jku/vendoring-compatible-imports
Vendoring-compatible imports
2 parents c2b1f0e + ab56344 commit b5c8ba0

15 files changed

+937
-924
lines changed

tuf/api/metadata.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
from securesystemslib.storage import FilesystemBackend, StorageBackendInterface
2525
from securesystemslib.util import persist_temp_file
2626

27-
import tuf.exceptions
28-
import tuf.formats
27+
from tuf import exceptions, formats
2928
from tuf.api.serialization import (
3029
MetadataDeserializer,
3130
MetadataSerializer,
@@ -266,10 +265,10 @@ def verify(
266265
)
267266

268267
if not signatures_for_keyid:
269-
raise tuf.exceptions.Error(f"no signature for key {key['keyid']}.")
268+
raise exceptions.Error(f"no signature for key {key['keyid']}.")
270269

271270
if len(signatures_for_keyid) > 1:
272-
raise tuf.exceptions.Error(
271+
raise exceptions.Error(
273272
f"{len(signatures_for_keyid)} signatures for key "
274273
f"{key['keyid']}, not sure which one to verify."
275274
)
@@ -337,7 +336,7 @@ def _common_fields_from_dict(signed_dict: Mapping[str, Any]) -> list:
337336
# Convert 'expires' TUF metadata string to a datetime object, which is
338337
# what the constructor expects and what we store. The inverse operation
339338
# is implemented in '_common_fields_to_dict'.
340-
expires = tuf.formats.expiry_string_to_datetime(expires_str)
339+
expires = formats.expiry_string_to_datetime(expires_str)
341340
return [_type, version, spec_version, expires]
342341

343342
def _common_fields_to_dict(self) -> Dict[str, Any]:

tuf/client/updater.py

+131-130
Large diffs are not rendered by default.

tuf/developer_tool.py

+72-70
Large diffs are not rendered by default.

tuf/download.py

+22-23
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@
3232
from __future__ import unicode_literals
3333

3434
import logging
35+
import six
3536
import timeit
3637
import tempfile
3738

38-
import securesystemslib
39-
import securesystemslib.util
40-
import six
39+
import securesystemslib # pylint: disable=unused-import
40+
from securesystemslib import formats as sslib_formats
4141

42-
import tuf
43-
import tuf.exceptions
44-
import tuf.formats
42+
from tuf import exceptions
43+
from tuf import formats
44+
from tuf import settings
4545

4646
# See 'log.py' to learn how logging is handled in TUF.
4747
logger = logging.getLogger(__name__)
@@ -53,7 +53,7 @@ def safe_download(url, required_length, fetcher):
5353
Given the 'url' and 'required_length' of the desired file, open a connection
5454
to 'url', download it, and return the contents of the file. Also ensure
5555
the length of the downloaded file matches 'required_length' exactly.
56-
tuf.download.unsafe_download() may be called if an upper download limit is
56+
download.unsafe_download() may be called if an upper download limit is
5757
preferred.
5858
5959
<Arguments>
@@ -86,8 +86,8 @@ def safe_download(url, required_length, fetcher):
8686

8787
# Do all of the arguments have the appropriate format?
8888
# Raise 'securesystemslib.exceptions.FormatError' if there is a mismatch.
89-
securesystemslib.formats.URL_SCHEMA.check_match(url)
90-
tuf.formats.LENGTH_SCHEMA.check_match(required_length)
89+
sslib_formats.URL_SCHEMA.check_match(url)
90+
formats.LENGTH_SCHEMA.check_match(required_length)
9191

9292
return _download_file(url, required_length, fetcher, STRICT_REQUIRED_LENGTH=True)
9393

@@ -101,7 +101,7 @@ def unsafe_download(url, required_length, fetcher):
101101
Given the 'url' and 'required_length' of the desired file, open a connection
102102
to 'url', download it, and return the contents of the file. Also ensure
103103
the length of the downloaded file is up to 'required_length', and no larger.
104-
tuf.download.safe_download() may be called if an exact download limit is
104+
download.safe_download() may be called if an exact download limit is
105105
preferred.
106106
107107
<Arguments>
@@ -134,8 +134,8 @@ def unsafe_download(url, required_length, fetcher):
134134

135135
# Do all of the arguments have the appropriate format?
136136
# Raise 'securesystemslib.exceptions.FormatError' if there is a mismatch.
137-
securesystemslib.formats.URL_SCHEMA.check_match(url)
138-
tuf.formats.LENGTH_SCHEMA.check_match(required_length)
137+
sslib_formats.URL_SCHEMA.check_match(url)
138+
formats.LENGTH_SCHEMA.check_match(required_length)
139139

140140
return _download_file(url, required_length, fetcher, STRICT_REQUIRED_LENGTH=False)
141141

@@ -208,15 +208,14 @@ def _download_file(url, required_length, fetcher, STRICT_REQUIRED_LENGTH=True):
208208
seconds_spent_receiving = stop_time - start_time
209209
average_download_speed = number_of_bytes_received / seconds_spent_receiving
210210

211-
if average_download_speed < tuf.settings.MIN_AVERAGE_DOWNLOAD_SPEED:
211+
if average_download_speed < settings.MIN_AVERAGE_DOWNLOAD_SPEED:
212212
logger.debug('The average download speed dropped below the minimum'
213-
' average download speed set in tuf.settings.py. Stopping the'
214-
' download!')
213+
' average download speed set in settings. Stopping the download!.')
215214
break
216215

217216
else:
218217
logger.debug('The average download speed has not dipped below the'
219-
' minimum average download speed set in tuf.settings.py.')
218+
' minimum average download speed set in settings.')
220219

221220
# Does the total number of downloaded bytes match the required length?
222221
_check_downloaded_length(number_of_bytes_received, required_length,
@@ -273,7 +272,7 @@ def _check_downloaded_length(total_downloaded, required_length,
273272
274273
tuf.exceptions.SlowRetrievalError, if the total downloaded was
275274
done in less than the acceptable download speed (as set in
276-
tuf.settings.py).
275+
tuf.settings).
277276
278277
<Returns>
279278
None.
@@ -296,24 +295,24 @@ def _check_downloaded_length(total_downloaded, required_length,
296295
# If the average download speed is below a certain threshold, we flag
297296
# this as a possible slow-retrieval attack.
298297
logger.debug('Average download speed: ' + repr(average_download_speed))
299-
logger.debug('Minimum average download speed: ' + repr(tuf.settings.MIN_AVERAGE_DOWNLOAD_SPEED))
298+
logger.debug('Minimum average download speed: ' + repr(settings.MIN_AVERAGE_DOWNLOAD_SPEED))
300299

301-
if average_download_speed < tuf.settings.MIN_AVERAGE_DOWNLOAD_SPEED:
302-
raise tuf.exceptions.SlowRetrievalError(average_download_speed)
300+
if average_download_speed < settings.MIN_AVERAGE_DOWNLOAD_SPEED:
301+
raise exceptions.SlowRetrievalError(average_download_speed)
303302

304303
else:
305304
logger.debug('Good average download speed: ' +
306305
repr(average_download_speed) + ' bytes per second')
307306

308-
raise tuf.exceptions.DownloadLengthMismatchError(required_length, total_downloaded)
307+
raise exceptions.DownloadLengthMismatchError(required_length, total_downloaded)
309308

310309
else:
311310
# We specifically disabled strict checking of required length, but we
312311
# will log a warning anyway. This is useful when we wish to download the
313312
# Timestamp or Root metadata, for which we have no signed metadata; so,
314313
# we must guess a reasonable required_length for it.
315-
if average_download_speed < tuf.settings.MIN_AVERAGE_DOWNLOAD_SPEED:
316-
raise tuf.exceptions.SlowRetrievalError(average_download_speed)
314+
if average_download_speed < settings.MIN_AVERAGE_DOWNLOAD_SPEED:
315+
raise exceptions.SlowRetrievalError(average_download_speed)
317316

318317
else:
319318
logger.debug('Good average download speed: ' +

0 commit comments

Comments
 (0)