コード例 #1
0
 def _make_bput(self, f, ctx, offset):
     bputnum = 1
     offset_next = offset + self.bput_size
     bput_next = readfile(f, offset_next, self.bput_size)
     bputcode = 200
     bputtext = {'ctx': ctx}
     try:
         bput_retries = int(self.cfg.bput_retries)
     except ValueError as e:
         warning(
             'parameter bput_retries is invalid, so use default value 3')
         bput_retries = 3
     while bput_next and bputnum < self.block_size / self.bput_size:
         bputcode, bputtext, _ = self._make_bput_post(
             ctx, bputnum, bput_next)
         while bput_retries and self.__need_retry(bputcode):
             bputcode, bputtext, _ = self._make_bput_post(
                 ctx, bputnum, bput_next)
             bput_retries -= 1
         if bputcode != 200:
             return offset, bputcode, bputtext['message']
         ctx = bputtext['ctx']
         offset_next = offset + bputtext['offset']
         bput_next = readfile(f, offset_next, self.bput_size)
         bputnum += 1
     return offset, bputcode, bputtext['ctx']
コード例 #2
0
 def _make_block(self, offset):
     url, size = self._mlk_url(offset)
     url = https_check(url)
     headers = self.__generate_headers()
     try:
         mkblk_retries = int(self.cfg.mkblk_retries)
     except ValueError as e:
         warning(
             'parameter mkblk_retries is invalid, so use default value 3')
         mkblk_retries = 3
     with open(self.path, 'rb') as f:
         bput = readfile(f, offset, self.bput_size)
         blkcode, blktext, _ = _post(url=url, headers=headers, data=bput)
         while mkblk_retries and self.__need_retry(blkcode):
             blkcode, blktext, _ = _post(url=url,
                                         headers=headers,
                                         data=bput)
             mkblk_retries -= 1
         if blkcode != 200:
             result = [offset, blkcode, blktext['message']]
             debug('make block fail,code :{0},message :{1}'.format(
                 blkcode, blktext))
         else:
             result = self._make_bput(f, blktext['ctx'], offset)
     self._record_upload_progress(result, size)
     return blkcode