Fix SHA256 mismatch when downloading with chunked transfer enconding

Switch to urllib2, urllib doesn't support chunked.
This commit is contained in:
Peter Melnichenko 2016-06-21 20:32:15 +03:00
parent 7c436e7632
commit a9b8ab94d9

View File

@ -20,9 +20,9 @@ import tempfile
import zipfile import zipfile
try: try:
from urllib import urlretrieve from urllib2 import urlopen
except ImportError: except ImportError:
from urllib.request import urlretrieve from urllib.request import urlopen
if os.name == "nt": if os.name == "nt":
try: try:
@ -98,6 +98,13 @@ def get_default_cache():
else: else:
return os.path.join(home, ".cache", "hererocks") return os.path.join(home, ".cache", "hererocks")
def download(url, filename):
response = urlopen(url)
data = response.read()
with open(filename, "wb") as out:
out.write(data)
def run(*args, **kwargs): def run(*args, **kwargs):
"""Execute a command. """Execute a command.
@ -394,7 +401,7 @@ class Program(object):
if not opts.downloads or not os.path.exists(archive_name): if not opts.downloads or not os.path.exists(archive_name):
print(message) print(message)
urlretrieve(url, archive_name) download(url, archive_name)
else: else:
print(message + " (cached)") print(message + " (cached)")