:returns: (str) a range string cut-off for the start-end range
an empty response means this window is out of range
"""
- assert start >= 0, '_range_up was called with start < 0'
- assert end >= start, '_range_up was called with end < start'
- assert end <= max_value, '_range_up was called with max_value < end'
+ assert start >= 0, '_range_up called w. start(%s) < 0' % start
+ assert end >= start, '_range_up called w. end(%s) < start(%s)' % (
+ end, start)
+ assert end <= max_value, '_range_up called w. max_value(%s) < end(%s)' % (
+ max_value, end)
if not a_range:
return '%s-%s' % (start, end)
selected = []
self.container = cnt_back_up
def purge_container(self, container=None):
- """Delete an empty container and destroy associated blocks
- """
+ """Delete an empty container and destroy associated blocks"""
cnt_back_up = self.container
try:
self.container = container or cnt_back_up
hash_gen = hash_cb(nblocks)
hash_gen.next()
- for i in range(nblocks):
+ for i in xrange(nblocks):
block = readall(fileobj, min(blocksize, size - offset))
bytes = len(block)
+ if bytes <= 0:
+ break
hash = _pithos_hash(block, blockhash)
hashes.append(hash)
hmap[hash] = (offset, bytes)
offset += bytes
if hash_cb:
hash_gen.next()
- msg = ('Failed to calculate uploaded blocks:'
- ' Offset and object size do not match')
+ msg = ('Failed to calculate uploading blocks: '
+ 'read bytes(%s) != requested size (%s)' % (offset, size))
assert offset == size, msg
def _upload_missing_blocks(self, missing, hmap, fileobj, upload_gen=None):
**restargs)
end = total_size - 1 if (
key + blocksize > total_size) else key + blocksize - 1
+ if end < key:
+ self._cb_next()
+ continue
data_range = _range_up(key, end, total_size, filerange)
if not data_range:
self._cb_next()
continue
- restargs['async_headers'] = {'Range': 'bytes=%s' % data_range}
+ restargs[
+ 'async_headers'] = {'Range': 'bytes=%s' % data_range}
flying[key] = self._get_block_async(obj, **restargs)
blockid_dict[key] = unsaved