~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tuned_gzip.py

  • Committer: Martin Pool
  • Date: 2008-04-24 07:22:53 UTC
  • mto: This revision was merged to the branch mainline in revision 3415.
  • Revision ID: mbp@sourcefrog.net-20080424072253-opmjij7xfy38w27f
Remove every assert statement from bzrlib!

Depending on the context they are:

 * turned into an explicit if/raise of either AssertionError 
   or something more specific -- particularly where they protect
   programming interfaces, complex invariants, or data file integrity
 * removed, if they're redundant with a later check, not protecting
   a meaningful invariant
 * turned into a selftest method on tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
149
149
 
150
150
        if buf == "":
151
151
            self._add_read_data(self.decompress.flush())
152
 
            assert len(self.decompress.unused_data) >= 8, "what does flush do?"
 
152
            if len(self.decompress.unused_data) < 8:
 
153
                raise AssertionError("what does flush do?")
153
154
            self._gzip_tail = self.decompress.unused_data[0:8]
154
155
            self._read_eof()
155
156
            # tell the driving read() call we have stuffed all the data
175
176
                self._gzip_tail = self.decompress.unused_data[0:8]
176
177
            elif seek_length < 0:
177
178
                # we haven't read enough to check the checksum.
178
 
                assert -8 < seek_length, "too great a seek."
 
179
                if not (-8 < seek_length):
 
180
                    raise AssertionError("too great a seek")
179
181
                buf = self.fileobj.read(-seek_length)
180
182
                self._gzip_tail = self.decompress.unused_data + buf
181
183
            else:
200
202
        # We then check the that the computed CRC and size of the
201
203
        # uncompressed data matches the stored values.  Note that the size
202
204
        # stored is the true file size mod 2**32.
203
 
        assert len(self._gzip_tail) == 8, "gzip trailer is incorrect length."
 
205
        if not (len(self._gzip_tail) == 8):
 
206
            raise AssertionError("gzip trailer is incorrect length.")
204
207
        crc32, isize = struct.unpack("<LL", self._gzip_tail)
205
208
        # note that isize is unsigned - it can exceed 2GB
206
209
        if crc32 != U32(self.crc):