Call _set_fileobj in AbstractDownloadItem.set_target
This commit is contained in:
parent
19c7d747dd
commit
b00c889dd1
@ -481,10 +481,14 @@ class AbstractDownloadItem(QObject):
|
|||||||
"""Ask a confirmation question for the download."""
|
"""Ask a confirmation question for the download."""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def _set_fileobj(self, fileobj):
|
def _set_fileobj(self, fileobj, *, autoclose=True):
|
||||||
"""Set a file object to save the download to.
|
"""Set a file object to save the download to.
|
||||||
|
|
||||||
Not supported by QtWebEngine.
|
Not supported by QtWebEngine.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
fileobj: The file object to download to.
|
||||||
|
autoclose: Close the file object automatically when it's done.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@ -567,8 +571,7 @@ class AbstractDownloadItem(QObject):
|
|||||||
target: The usertypes.DownloadTarget for this download.
|
target: The usertypes.DownloadTarget for this download.
|
||||||
"""
|
"""
|
||||||
if isinstance(target, usertypes.FileObjDownloadTarget):
|
if isinstance(target, usertypes.FileObjDownloadTarget):
|
||||||
raise UnsupportedOperationError("FileObjDownloadTarget is "
|
self._set_fileobj(target.fileobj, autoclose=False)
|
||||||
"unsupported")
|
|
||||||
elif isinstance(target, usertypes.FileDownloadTarget):
|
elif isinstance(target, usertypes.FileDownloadTarget):
|
||||||
self._set_filename(target.filename)
|
self._set_filename(target.filename)
|
||||||
elif isinstance(target, usertypes.OpenFileDownloadTarget):
|
elif isinstance(target, usertypes.OpenFileDownloadTarget):
|
||||||
|
@ -186,7 +186,7 @@ class DownloadItem(downloads.AbstractDownloadItem):
|
|||||||
no_action=no_action, cancel_action=no_action,
|
no_action=no_action, cancel_action=no_action,
|
||||||
abort_on=[self.cancelled, self.error])
|
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.
|
""""Set the file object to write the download to.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -196,6 +196,7 @@ class DownloadItem(downloads.AbstractDownloadItem):
|
|||||||
raise ValueError("fileobj was already set! Old: {}, new: "
|
raise ValueError("fileobj was already set! Old: {}, new: "
|
||||||
"{}".format(self.fileobj, fileobj))
|
"{}".format(self.fileobj, fileobj))
|
||||||
self.fileobj = fileobj
|
self.fileobj = fileobj
|
||||||
|
self.autoclose = autoclose
|
||||||
try:
|
try:
|
||||||
self._read_timer.stop()
|
self._read_timer.stop()
|
||||||
log.downloads.debug("buffer: {} bytes".format(self._buffer.tell()))
|
log.downloads.debug("buffer: {} bytes".format(self._buffer.tell()))
|
||||||
@ -333,13 +334,6 @@ class DownloadItem(downloads.AbstractDownloadItem):
|
|||||||
old_reply.deleteLater()
|
old_reply.deleteLater()
|
||||||
return True
|
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):
|
class DownloadManager(downloads.AbstractDownloadManager):
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user