Skip to content

Commit

Permalink
Add callback to consume data for unsupported content download
Browse files Browse the repository at this point in the history
  • Loading branch information
EvaSDK committed Dec 28, 2016
1 parent 89d97e4 commit d444752
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ghost/ghost.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,14 @@ def reply_ready_peek(reply):
reply.data += reply.peek(reply.bytesAvailable())


def reply_ready_read(reply):
"""Consume data from `reply` buffer.
:param reply: QNetworkReply object.
"""
reply.readAll()


class NetworkAccessManager(QNetworkAccessManager):
"""Subclass QNetworkAccessManager to always cache the reply content
Expand Down Expand Up @@ -1344,6 +1352,10 @@ def _request_ended(self, reply):

def _unsupported_content(self, reply):
self.logger.info("Unsupported content %s", str(reply.url()))
# reply went though reply_read_peek already, consume buffer to avoid
# duplication on next signal handling and connect callback
reply_ready_read(reply)
reply.readyRead.connect(partial(reply_ready_read, reply))

def _on_manager_ssl_errors(self, reply, errors):
url = unicode(reply.url().toString())
Expand Down

0 comments on commit d444752

Please sign in to comment.