Skip to content

Commit 6076c8d

Browse files
Revert "try to fix http_download"
This reverts commit f1cb16a.
1 parent f1cb16a commit 6076c8d

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lib/inputstreamhelper/utils.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,12 @@ def download_path(url):
7272

7373
return os.path.join(temp_path(), filename)
7474

75+
76+
7577
def _http_request(url, headers=None, time_out=10):
76-
"""Perform an HTTP request and return the response object and content."""
77-
if headers is None:
78-
headers = {}
78+
"""Perform an HTTP request and return the response and content."""
79+
headers = headers or {}
80+
7981
log(0, 'Request URL: {url}', url=url)
8082
request = Request(url, headers=headers)
8183

@@ -84,14 +86,14 @@ def _http_request(url, headers=None, time_out=10):
8486
log(0, 'Response code: {code}', code=response.getcode())
8587
if 400 <= response.getcode() < 600:
8688
raise HTTPError(url, response.getcode(), f'HTTP {response.getcode()} Error for url: {url}', response.headers, None)
89+
# Read the content inside the `with` block
8790
content = response.read()
88-
# Return both response object and content
8991
return response, content
9092
except (HTTPError, URLError) as err:
9193
log(2, 'Download failed with error {}'.format(err))
9294
if yesno_dialog(localize(30004), '{line1}\n{line2}'.format(line1=localize(30063), line2=localize(30065))): # Internet down, try again?
9395
return _http_request(url, headers, time_out)
94-
return None, None
96+
return None
9597

9698
def http_get(url):
9799
"""Perform an HTTP GET request and return content."""
@@ -129,7 +131,7 @@ def http_download(url, message=None, checksum=None, hash_alg='sha1', dl_size=Non
129131
log(4, 'Invalid hash algorithm specified: {}'.format(hash_alg))
130132
checksum = None
131133

132-
req, _ = _http_request(url)
134+
req = _http_request(url)
133135
if req is None:
134136
return None
135137

@@ -164,7 +166,7 @@ def http_download(url, message=None, checksum=None, hash_alg='sha1', dl_size=Non
164166
return False
165167

166168
headers = {'Range': 'bytes={}-{}'.format(size, total_length)}
167-
req, _ = _http_request(url, headers=headers)
169+
req = _http_request(url, headers=headers)
168170
if req is None:
169171
return None
170172
continue

0 commit comments

Comments
 (0)