change required parameter type to file-like objects

pull/13/head
Mike Fährmann 9 years ago
parent 5a8541afa5
commit ecc6542fc8
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

@ -15,16 +15,18 @@ class BasicDownloader():
max_tries = 5
def download(self, url, path):
"""Download the resource at 'url' and write it to a file given by 'path'"""
with open(path, "wb") as file:
def download(self, url, fileobj):
"""Download the resource at 'url' and write it to a file-like object"""
try:
return self.download_impl(url, fileobj)
except:
# remove file if download failed
try:
return self.download_impl(url, file)
except:
#remove file if download failed
file.close()
os.unlink(path)
raise
fileobj.close()
os.unlink(fileobj.name)
except AttributeError:
pass
raise
def download_impl(self, url, file_handle):
"""Actual implementaion of the download process"""

@ -93,7 +93,8 @@ class DownloadJob(Job):
return
dlinstance = self.get_downloader(url)
self.printer.start(path)
tries = dlinstance.download(url, path)
with open(path, "wb") as file:
tries = dlinstance.download(url, file)
self.printer.success(path, tries)
def set_directory(self, msg):

Loading…
Cancel
Save