Пример #1
0
 def _get_response(self, writer):
     # spawned in a coroutine to read the HTTP response
     try:
         resp = writer.getresponse()
     except (Exception, Timeout) as exc:
         resp = None
         msg = str(exc)
         self.logger.warn("Failed to read response for %s (reqid=%s): %s",
                          writer.chunk, self.reqid, msg)
         writer.chunk['error'] = 'resp: %s' % msg
     # close_source() will be called in a finally block later.
     # But we do not want to wait for all writers to have finished writing
     # before closing connections.
     io.close_source(writer, self.logger)
     return (writer, resp)
Пример #2
0
 def _dispatch_response(self, writer, resp, success_chunks, failed_chunks):
     if resp:
         if resp.status == 201:
             checksum = resp.getheader(CHUNK_HEADERS['chunk_hash'])
             if checksum and writer.checksum and \
                     checksum.lower() != writer.checksum.hexdigest():
                 writer.chunk['error'] = \
                     "checksum mismatch: %s (local), %s (rawx)" % \
                     (checksum.lower(), writer.checksum.hexdigest())
                 failed_chunks.append(writer.chunk)
             else:
                 success_chunks.append(writer.chunk)
         else:
             logger.error("Wrong status code from %s (%s) %s",
                          writer.chunk, resp.status, resp.reason)
             writer.chunk['error'] = 'resp: HTTP %s' % resp.status
             failed_chunks.append(writer.chunk)
     else:
         failed_chunks.append(writer.chunk)
     io.close_source(writer)
Пример #3
0
 def _close_writers(self, writers):
     """Explicitly close all chunk writers."""
     for writer in writers:
         io.close_source(writer, self.logger)