1111# Imports
1212import requests
1313import 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
1818from 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