Move actual session.get call into separate function
By moving this call (and its long explanation) to a separate function,
diffs for later refactoring will be easier to review.
@@ -428,17 +428,9 @@ def _get_http_response_filename(resp, link):
return filename
-def _download_http_url(
- link, # type: Link
- session, # type: PipSession
- temp_dir, # type: str
- hashes, # type: Optional[Hashes]
- progress_bar # type: str
-):
- # type: (...) -> Tuple[str, str]
- """Download link url into temp_dir using provided session"""
+def _http_get_download(session, link):
+ # type: (PipSession, Link) -> Response
target_url = link.url.split('#', 1)[0]
- try:
resp = session.get(
target_url,
# We use Accept-Encoding: identity here because requests
@@ -464,6 +456,20 @@ def _download_http_url(
stream=True,
)
resp.raise_for_status()
+ return resp
+
+
+def _download_http_url(
+ link, # type: Link
+ session, # type: PipSession
+ temp_dir, # type: str
+ hashes, # type: Optional[Hashes]
+ progress_bar # type: str
+):
+ # type: (...) -> Tuple[str, str]
+ """Download link url into temp_dir using provided session"""
+ try:
+ resp = _http_get_download(session, link)
except requests.HTTPError as exc:
logger.critical(
"HTTP error %s while getting %s", exc.response.status_code, link,
