|
12 | 12 |
|
13 | 13 | if sys.version_info[0] == 2: |
14 | 14 | from urlparse import urlparse |
15 | | - import requests |
| 15 | + from urllib2 import urlopen # noqa f811 |
16 | 16 | else: |
17 | 17 | from urllib.request import urlopen |
18 | 18 | from urllib.parse import urlparse # noqa: F401 |
@@ -95,10 +95,7 @@ def _download_archive_zip(url, filename): |
95 | 95 | sys.stderr.write('Downloading: \"{}\" to {}\n'.format(url, filename)) |
96 | 96 | # We use a different API for python2 since urllib(2) doesn't recognize the CA |
97 | 97 | # certificates in older Python |
98 | | - if sys.version_info[0] == 2: |
99 | | - response = requests.get(url, stream=True).raw |
100 | | - else: |
101 | | - response = urlopen(url) |
| 98 | + response = urlopen(url) |
102 | 99 | with open(filename, 'wb') as f: |
103 | 100 | while True: |
104 | 101 | data = response.read(READ_DATA_CHUNK) |
@@ -376,22 +373,14 @@ def _download_url_to_file(url, dst, hash_prefix, progress): |
376 | 373 | file_size = None |
377 | 374 | # We use a different API for python2 since urllib(2) doesn't recognize the CA |
378 | 375 | # certificates in older Python |
379 | | - if sys.version_info[0] == 2: |
380 | | - response = requests.get(url, stream=True) |
381 | | - |
382 | | - content_length = response.headers['Content-Length'] |
383 | | - file_size = int(content_length) |
384 | | - u = response.raw |
| 376 | + u = urlopen(url) |
| 377 | + meta = u.info() |
| 378 | + if hasattr(meta, 'getheaders'): |
| 379 | + content_length = meta.getheaders("Content-Length") |
385 | 380 | else: |
386 | | - u = urlopen(url) |
387 | | - |
388 | | - meta = u.info() |
389 | | - if hasattr(meta, 'getheaders'): |
390 | | - content_length = meta.getheaders("Content-Length") |
391 | | - else: |
392 | | - content_length = meta.get_all("Content-Length") |
393 | | - if content_length is not None and len(content_length) > 0: |
394 | | - file_size = int(content_length[0]) |
| 381 | + content_length = meta.get_all("Content-Length") |
| 382 | + if content_length is not None and len(content_length) > 0: |
| 383 | + file_size = int(content_length[0]) |
395 | 384 |
|
396 | 385 | # We deliberately save it in a temp file and move it after |
397 | 386 | # download is complete. This prevents a local working checkpoint |
|
0 commit comments