11
11
# Imports
12
12
import requests
13
13
import six
14
- import urllib3 .exceptions
14
+ import urllib3 .exceptions as urllib3_ex
15
15
16
- import tuf . exceptions
17
- import tuf . settings
16
+ import tuf
17
+ from tuf import exceptions , settings
18
18
from tuf .client_rework .fetcher import FetcherInterface
19
19
20
20
# Globals
@@ -58,9 +58,9 @@ def fetch(self, url, required_length):
58
58
bytes.
59
59
60
60
Raises:
61
- tuf. exceptions.SlowRetrievalError: A timeout occurs while receiving
61
+ exceptions.SlowRetrievalError: A timeout occurs while receiving
62
62
data.
63
- tuf. exceptions.FetcherHTTPError: An HTTP error code is received.
63
+ exceptions.FetcherHTTPError: An HTTP error code is received.
64
64
65
65
Returns:
66
66
A bytes iterator
@@ -76,15 +76,15 @@ def fetch(self, url, required_length):
76
76
# - connect timeout (max delay before first byte is received)
77
77
# - read (gap) timeout (max delay between bytes received)
78
78
response = session .get (
79
- url , stream = True , timeout = tuf . settings .SOCKET_TIMEOUT
79
+ url , stream = True , timeout = settings .SOCKET_TIMEOUT
80
80
)
81
81
# Check response status.
82
82
try :
83
83
response .raise_for_status ()
84
84
except requests .HTTPError as e :
85
85
response .close ()
86
86
status = e .response .status_code
87
- raise tuf . exceptions .FetcherHTTPError (str (e ), status )
87
+ raise exceptions .FetcherHTTPError (str (e ), status )
88
88
89
89
# Define a generator function to be returned by fetch. This way the
90
90
# caller of fetch can differentiate between connection and actual data
@@ -99,11 +99,11 @@ def chunks():
99
99
# large file in one shot. Before beginning the round, sleep
100
100
# (if set) for a short amount of time so that the CPU is
101
101
# 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 )
104
104
105
105
read_amount = min (
106
- tuf . settings .CHUNK_SIZE ,
106
+ settings .CHUNK_SIZE ,
107
107
required_length - bytes_received ,
108
108
)
109
109
@@ -130,8 +130,8 @@ def chunks():
130
130
if bytes_received >= required_length :
131
131
break
132
132
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 ))
135
135
136
136
finally :
137
137
response .close ()
@@ -147,7 +147,7 @@ def _get_session(self, url):
147
147
parsed_url = six .moves .urllib .parse .urlparse (url )
148
148
149
149
if not parsed_url .scheme or not parsed_url .hostname :
150
- raise tuf . exceptions .URLParsingError (
150
+ raise exceptions .URLParsingError (
151
151
"Could not get scheme and hostname from URL: " + url
152
152
)
153
153
0 commit comments