Ticket #1418: preconditions-about-ticket1418.diff

File preconditions-about-ticket1418.diff, 3.6 KB (added by zooko, at 2011-06-21T17:54:17Z)
  • .8.2/src/allmydata/immutable/encode.py

    diff -rN -u old-1.8.2/src/allmydata/immutable/encode.py new-1.8.2/src/allmydata/immutable/encode.py
    old new  
    105105        def _got_size(size):
    106106            self.log(format="file size: %(size)d", size=size)
    107107            self.file_size = size
     108            precondition(isinstance(self.file_size, (int, long)), self.file_size)
    108109        d.addCallback(_got_size)
    109110        d.addCallback(lambda res: eu.get_all_encoding_parameters())
    110111        d.addCallback(self._got_all_encoding_parameters)
     
    118119    def _got_all_encoding_parameters(self, params):
    119120        assert not self._codec
    120121        k, happy, n, segsize = params
     122        precondition(isinstance(segsize, (int, long)), segsize)
    121123        self.required_shares = k
    122124        self.servers_of_happiness = happy
    123125        self.num_shares = n
     
    129131
    130132        self.num_segments = mathutil.div_ceil(self.file_size,
    131133                                              self.segment_size)
     134        precondition(isinstance(self.num_segments, (int, long)), self.num_segments)
    132135
    133136        self._codec = CRSEncoder()
    134137        self._codec.set_params(self.segment_size,
  • .8.2/src/allmydata/immutable/upload.py

    diff -rN -u old-1.8.2/src/allmydata/immutable/upload.py new-1.8.2/src/allmydata/immutable/upload.py
    old new  
    608608        d = self.original.get_all_encoding_parameters()
    609609        def _got(encoding_parameters):
    610610            (k, happy, n, segsize) = encoding_parameters
     611            precondition(isinstance(segsize, (int, long)), segsize)
    611612            self._segment_size = segsize # used by segment hashers
    612613            self._encoding_parameters = encoding_parameters
    613614            self.log("my encoding parameters: %s" % (encoding_parameters,),
     
    915916        share_size = encoder.get_param("share_size")
    916917        block_size = encoder.get_param("block_size")
    917918        num_segments = encoder.get_param("num_segments")
     919        precondition(isinstance(num_segments, (int, long)), num_segments)
    918920        k,desired,n = encoder.get_param("share_counts")
    919921
    920922        self._peer_selection_started = time.time()
     
    12701272        if self._all_encoding_parameters:
    12711273            return defer.succeed(self._all_encoding_parameters)
    12721274
     1275        precondition(self.max_segment_size is None or isinstance(self.max_segment_size, (int, long)), self.max_segment_size)
     1276        precondition(isinstance(self.default_max_segment_size, (int, long)), self.default_max_segment_size)
    12731277        max_segsize = self.max_segment_size or self.default_max_segment_size
    12741278        k = self.encoding_param_k or self.default_encoding_param_k
    12751279        happy = self.encoding_param_happy or self.default_encoding_param_happy
     
    12771281
    12781282        d = self.get_size()
    12791283        def _got_size(file_size):
     1284            precondition(isinstance(file_size, (int, long)), file_size)
    12801285            # for small files, shrink the segment size to avoid wasting space
    12811286            segsize = min(max_segsize, file_size)
     1287            precondition(isinstance(segsize, (int, long)), segsize)
    12821288            # this must be a multiple of 'required_shares'==k
    12831289            segsize = mathutil.next_multiple(segsize, k)
     1290            precondition(isinstance(segsize, (int, long)), segsize)
    12841291            encoding_parameters = (k, happy, n, segsize)
    12851292            self._all_encoding_parameters = encoding_parameters
    12861293            return encoding_parameters