args = locals().copy()
for elem in ['self', 'container', 'object']:
args.pop(elem)
- data = self.retrieve_object(container, object, format='json', **args)
- return data['hashes']
+ return self.retrieve_object(container, object, format='json', **args)
def create_directory_marker(self, container, object, account=None):
"""creates a dierectory marker"""
def download(client, container, object, path):
- meta = client.retrieve_container_metadata(container)
- blocksize = int(meta['x-container-block-size'])
- blockhash = meta['x-container-block-hash']
+ res = client.retrieve_object_hashmap(container, object)
+ blocksize = int(res['block_size'])
+ blockhash = res['block_hash']
+ bytes = res['bytes']
+ map = res['hashes']
+ print res
if os.path.exists(path):
- size = os.path.getsize(path)
- hashes = HashMap(blocksize, blockhash)
- hashes.load(open(path))
+ h = HashMap(blocksize, blockhash)
+ h.load(open(path))
+ hashes = [hexlify(x) for x in h]
else:
open(path, 'w').close() # Create an empty file
- size = 0
hashes = []
- map = client.retrieve_object_hashmap(container, object)
+ if bytes == 0:
+ return
- with open(path, 'a') as fp:
+ with open(path, 'a+') as fp:
for i, h in enumerate(map):
if i < len(hashes) and h == hashes[i]:
continue
start = i * blocksize
- end = '' if i == len(map) - 1 else (i + 1) * blocksize
+ end = '' if i == len(map) - 1 else ((i + 1) * blocksize) - 1
data = client.retrieve_object(container, object, range='bytes=%s-%s' % (start, end))
+ if i != len(map) - 1:
+ data += (blocksize - len(data)) * '\x00'
fp.seek(start)
fp.write(data)
o = 'object'
zero = self.client.create_zero_length_object(c, o)
zero_meta = self.client.retrieve_object_metadata(c, o)
- zero_hash = self.client.retrieve_object_hashmap(c, o)
+ zero_hash = self.client.retrieve_object_hashmap(c, o)["hashes"]
zero_data = self.client.retrieve_object(c, o)
self.assertEqual(int(zero_meta['content-length']), 0)
source_data = self.client.retrieve_object(c, src)
source_meta = self.client.retrieve_object_metadata(c, src)
- source_hash = self.client.retrieve_object_hashmap(c, src)
+ source_hash = self.client.retrieve_object_hashmap(c, src)["hashes"]
#update zero length object
self.client.create_zero_length_object(c, dest)
self.client.update_from_other_source(c, dest, source_object)
dest_data = self.client.retrieve_object(c, src)
dest_meta = self.client.retrieve_object_metadata(c, dest)
- dest_hash = self.client.retrieve_object_hashmap(c, src)
+ dest_hash = self.client.retrieve_object_hashmap(c, src)["hashes"]
self.assertEqual(source_data, dest_data)
self.assertEqual(source_hash, dest_hash)
self.assertEqual(self.client.retrieve_object(c, o),
self.client.retrieve_object(c, other))
- self.assertEqual(self.client.retrieve_object_hashmap(c, o),
- self.client.retrieve_object_hashmap(c, other))
+ self.assertEqual(self.client.retrieve_object_hashmap(c, o)["hashes"],
+ self.client.retrieve_object_hashmap(c, other)["hashes"])
class ObjectDelete(BaseTestCase):
def setUp(self):