Skip to content

Commit

Permalink
download fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kiorky committed Apr 25, 2014
1 parent 79ac5bb commit 3f94695
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
Expand Up @@ -3,7 +3,7 @@ CHANGELOG
2.16 (unreleased)
-----------------

- Nothing changed yet.
- fix a bug in download, reply can be not finished to read on exit


2.15 (2013-07-16)
Expand Down
17 changes: 15 additions & 2 deletions src/spynner/browser.py
Expand Up @@ -399,12 +399,25 @@ def _on_ready_read():
def _on_network_error():
self._debug(ERROR, "Network error on download: %s" % url)
def _on_finished():
data = reply.readAll()
if len(data):
if getattr(reply, 'downloaded_nbytes at end', None) is None:
reply.downloaded_nbytes= 0
reply.downloaded_nbytes += len(data)
outfd.write(data)
self._debug(DEBUG, "Read from download stream at end (%d bytes): %s"
% (len(data), url))
suf = ''
if path is not None:
outfd.flush()
dict(self.files)[path]['finished'] = True
self._debug(INFO, "Download finished: %s" % url)
suf = ' in {0}'.format(path)
self._debug(INFO, "Download finished: {0}{1}".format(url, path))

if path is not None:
self.files.append((path, {'reply':reply,'finished':False,}))
self.files.append((path, {'reply':reply,
'readed': False,
'finished':False,}))
reply.readyRead.connect(_on_ready_read)
reply.error.connect(_on_network_error)
reply.finished.connect(_on_finished)
Expand Down

0 comments on commit 3f94695

Please sign in to comment.