def from_reply(cls, reply: QtNetwork.QNetworkReply) -> 'Response': """Slowly populates a new Response object with data from the request.""" r = cls() # Signal mapping reply.metaDataChanged.connect(functools.partial(r._insert_headers, reply.rawHeaderPairs())) reply.redirected.connect(r._insert_url) reply.error.connect(r._update_code) reply.error.connect(functools.partial(r._update_error_string, reply.errorString())) # Wait until the request is finished before continuing signals.wait_for_signal(reply.finished) # Strip the remaining data from the reply, then mark it for deletion r._from_reply(reply) reply.close() reply.deleteLater() # Return the object return r