def write(self, buf): """ writes response """ if self.rep.tell() > 1000000 or self.doAbort: rep = self.getResponse() if self.doAbort: raise Abort() f = open("response.dump", "wb") f.write(rep) f.close() raise Exception("Loaded Url exceeded limit") self.rep.write(buf)
# calc speed once per second, averaging over 3 seconds if lastTimeCheck + 1 < t: diff = [ c.arrived - (self.lastArrived[i] if len(self.lastArrived) > i else 0) for i, c in enumerate(self.chunks) ] self.lastSpeeds[1] = self.lastSpeeds[0] self.lastSpeeds[0] = self.speeds self.speeds = [float(a) / (t - lastTimeCheck) for a in diff] self.lastArrived = [c.arrived for c in self.chunks] lastTimeCheck = t if self.doAbort: raise Abort() self.m.select(1) for chunk in self.chunks: chunk.flushFile() #make sure downloads are written to disk self._copyChunks() def findChunk(self, handle): """ linear search to find a chunk (should be ok since chunk size is usually low) """ for chunk in self.chunks: if chunk.c == handle: return chunk def closeChunk(self, chunk): try: