From: Brian Warner Date: Sat, 14 Jul 2007 02:30:48 +0000 (-0700) Subject: storage.py: turn some assertions into preconditions X-Git-Url: https://git.rkrishnan.org/vdrive/$sch_link?a=commitdiff_plain;h=8a39ee90343f8104c8eff6e0a9520a1e9ece0073;p=tahoe-lafs%2Ftahoe-lafs.git storage.py: turn some assertions into preconditions --- diff --git a/src/allmydata/storage.py b/src/allmydata/storage.py index 80196807..4b0fccfa 100644 --- a/src/allmydata/storage.py +++ b/src/allmydata/storage.py @@ -241,24 +241,33 @@ class WriteBucketProxy: offset = self._offsets['plaintext_hash_tree'] assert isinstance(hashes, list) data = "".join(hashes) - assert len(data) == self._segment_hash_size - assert offset + len(data) <= self._offsets['crypttext_hash_tree'] + precondition(len(data) == self._segment_hash_size, + len(data), self._segment_hash_size) + precondition(offset+len(data) <= self._offsets['crypttext_hash_tree'], + offset, len(data), offset+len(data), + self._offsets['crypttext_hash_tree']) return self._write(offset, data) def put_crypttext_hashes(self, hashes): offset = self._offsets['crypttext_hash_tree'] assert isinstance(hashes, list) data = "".join(hashes) - assert len(data) == self._segment_hash_size - assert offset + len(data) <= self._offsets['block_hashes'] + precondition(len(data) == self._segment_hash_size, + len(data), self._segment_hash_size) + precondition(offset + len(data) <= self._offsets['block_hashes'], + offset, len(data), offset+len(data), + self._offsets['block_hashes']) return self._write(offset, data) def put_block_hashes(self, blockhashes): offset = self._offsets['block_hashes'] assert isinstance(blockhashes, list) data = "".join(blockhashes) - assert len(data) == self._segment_hash_size - assert offset + len(data) <= self._offsets['share_hashes'] + precondition(len(data) == self._segment_hash_size, + len(data), self._segment_hash_size) + precondition(offset + len(data) <= self._offsets['share_hashes'], + offset, len(data), offset+len(data), + self._offsets['share_hashes']) return self._write(offset, data) def put_share_hashes(self, sharehashes): @@ -270,13 +279,16 @@ class WriteBucketProxy: for hashnum,hashvalue in sharehashes]) precondition(len(data) == self._share_hash_size, len(data), self._share_hash_size) - assert offset + len(data) <= self._offsets['uri_extension'] + precondition(offset + len(data) <= self._offsets['uri_extension'], + offset, len(data), offset+len(data), + self._offsets['uri_extension']) return self._write(offset, data) def put_uri_extension(self, data): offset = self._offsets['uri_extension'] assert isinstance(data, str) - assert len(data) <= self._uri_extension_size + precondition(len(data) <= self._uri_extension_size, + len(data), self._uri_extension_size) length = struct.pack(">L", len(data)) return self._write(offset, length+data)