Split _die in two methods

We need to do some stuff before AbstractDownloadItem._die runs.
This commit is contained in:
Florian Bruhin 2016-11-01 18:02:54 +01:00
parent 6eef79e180
commit a3a167e683
2 changed files with 6 additions and 2 deletions

View File

@ -327,6 +327,10 @@ class AbstractDownloadItem(QObject):
remaining=remaining, perc=perc, down=down,
total=total, errmsg=errmsg))
def _do_die(self):
"""Do cleanup steps after a download has died."""
raise NotImplementedError
def _die(self, msg):
"""Abort the download and emit an error."""
assert not self.successful
@ -350,6 +354,7 @@ class AbstractDownloadItem(QObject):
if self._dead:
return
self._dead = True
self._do_die()
self.error_msg = msg
self.stats.finish()
self.error.emit(msg)

View File

@ -118,9 +118,8 @@ class DownloadItem(downloads.AbstractDownloadItem):
no_action=no_action, cancel_action=no_action,
abort_on=[self.cancelled, self.error])
def _die(self, msg):
def _do_die(self):
"""Abort the download and emit an error."""
super()._die(msg)
self._read_timer.stop()
self._reply.downloadProgress.disconnect()
self._reply.finished.disconnect()