Esempio n. 1
0
    def close(self):
        if self.fp:
            self.md5_read = self.iter_md5.hexdigest()
            if self.bytes_read != self.size:
                raise exc.FaultyChunk('Invalid size for chunk')

            if self.md5_read != self.md5_checksum:
                raise exc.CorruptedChunk('checksum does not match %s != %s' %
                                         (self.md5_read, self.md5_checksum))
Esempio n. 2
0
    def close(self):
        """
        Perform checks on what has been read before closing,
        if no error has occurred yet.
        """
        if self.fp and not self.error:
            md5_read = self.iter_md5.hexdigest()
            if self.bytes_read != self.size:
                raise exc.FaultyChunk('Invalid size: expected %d, got %d' %
                                      (self.size, self.bytes_read))

            if md5_read != self.md5_checksum:
                raise exc.CorruptedChunk('checksum does not match %s != %s' %
                                         (md5_read, self.md5_checksum))
Esempio n. 3
0
 def __iter__(self):
     self.iter_md5 = hashlib.md5()
     while True:
         buf = self.fp.read()
         if buf and self.decompressor:
             try:
                 buf = self.decompressor.decompress(buf)
             except zlib.error as zerr:
                 self.error = exc.CorruptedChunk(zerr)
                 raise self.error
         if buf:
             self.iter_md5.update(buf)
             self.bytes_read += len(buf)
             yield buf
         else:
             break