Skip to content

Commit

Permalink
imports: Handle remaining incompatible imports
Browse files Browse the repository at this point in the history
Import specific exceptions from urllib3 & requests to be compatible
with vendoring. Also organize imports so tuf internal imports are last.

Signed-off-by: Jussi Kukkonen <[email protected]>
  • Loading branch information
Jussi Kukkonen committed Jan 12, 2021
1 parent 61f1fe0 commit f647fa7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
8 changes: 4 additions & 4 deletions tuf/client/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,11 @@
import time
import fnmatch
import copy
from requests.exceptions import HTTPError
import six
import warnings


from securesystemslib import exceptions as sslib_exceptions
from securesystemslib import formats as sslib_formats
from securesystemslib import hash as sslib_hash
Expand All @@ -146,9 +149,6 @@
from tuf import settings
from tuf import sig

import six
import requests.exceptions

# The Timestamp role does not have signed metadata about it; otherwise we
# would need an infinite regress of metadata. Therefore, we use some
# default, but sane, upper file length for its metadata.
Expand Down Expand Up @@ -1114,7 +1114,7 @@ def _update_root_metadata(self, current_root_metadata):
"""

def neither_403_nor_404(mirror_error):
if isinstance(mirror_error, requests.exceptions.HTTPError):
if isinstance(mirror_error, HTTPError):
if mirror_error.response.status_code in {403, 404}:
return False
return True
Expand Down
10 changes: 4 additions & 6 deletions tuf/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,18 @@
import time
import timeit
import tempfile

import tuf
import requests
import six
from urllib3.exceptions import ReadTimeoutError

import securesystemslib
from securesystemslib import formats as sslib_formats
import six

import tuf
from tuf import exceptions
from tuf import formats
from tuf import settings

import urllib3.exceptions

# See 'log.py' to learn how logging is handled in TUF.
logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -375,7 +373,7 @@ def _download_fixed_amount_of_data(response, temp_file, required_length):
# Finally, we signal that the download is complete.
break

except urllib3.exceptions.ReadTimeoutError as e:
except ReadTimeoutError as e:
raise exceptions.SlowRetrievalError(str(e))

return number_of_bytes_received, average_download_speed
Expand Down

0 comments on commit f647fa7

Please sign in to comment.