From b00c889dd176ad091398e410c0801cd34d613db0 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 8 Nov 2016 20:33:25 +0100 Subject: [PATCH] Call _set_fileobj in AbstractDownloadItem.set_target --- qutebrowser/browser/downloads.py | 9 ++++++--- qutebrowser/browser/qtnetworkdownloads.py | 10 ++-------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/qutebrowser/browser/downloads.py b/qutebrowser/browser/downloads.py index 8684c6c13..a4018aa04 100644 --- a/qutebrowser/browser/downloads.py +++ b/qutebrowser/browser/downloads.py @@ -481,10 +481,14 @@ class AbstractDownloadItem(QObject): """Ask a confirmation question for the download.""" raise NotImplementedError - def _set_fileobj(self, fileobj): + def _set_fileobj(self, fileobj, *, autoclose=True): """Set a file object to save the download to. Not supported by QtWebEngine. + + Args: + fileobj: The file object to download to. + autoclose: Close the file object automatically when it's done. """ raise NotImplementedError @@ -567,8 +571,7 @@ class AbstractDownloadItem(QObject): target: The usertypes.DownloadTarget for this download. """ if isinstance(target, usertypes.FileObjDownloadTarget): - raise UnsupportedOperationError("FileObjDownloadTarget is " - "unsupported") + self._set_fileobj(target.fileobj, autoclose=False) elif isinstance(target, usertypes.FileDownloadTarget): self._set_filename(target.filename) elif isinstance(target, usertypes.OpenFileDownloadTarget): diff --git a/qutebrowser/browser/qtnetworkdownloads.py b/qutebrowser/browser/qtnetworkdownloads.py index 10fd4dafc..fd62c8ffc 100644 --- a/qutebrowser/browser/qtnetworkdownloads.py +++ b/qutebrowser/browser/qtnetworkdownloads.py @@ -186,7 +186,7 @@ class DownloadItem(downloads.AbstractDownloadItem): no_action=no_action, cancel_action=no_action, abort_on=[self.cancelled, self.error]) - def _set_fileobj(self, fileobj): + def _set_fileobj(self, fileobj, *, autoclose=True): """"Set the file object to write the download to. Args: @@ -196,6 +196,7 @@ class DownloadItem(downloads.AbstractDownloadItem): raise ValueError("fileobj was already set! Old: {}, new: " "{}".format(self.fileobj, fileobj)) self.fileobj = fileobj + self.autoclose = autoclose try: self._read_timer.stop() log.downloads.debug("buffer: {} bytes".format(self._buffer.tell())) @@ -333,13 +334,6 @@ class DownloadItem(downloads.AbstractDownloadItem): old_reply.deleteLater() return True - def set_target(self, target): - if isinstance(target, usertypes.FileObjDownloadTarget): - self._set_fileobj(target.fileobj) - self.autoclose = False - else: - super().set_target(target) - class DownloadManager(downloads.AbstractDownloadManager):