Permalink
Browse files

Bug Fixes

The listing functions (container.objects() and client.containers()) now use the special subdirs when provided when listing with the pseudo-hierarchy.
Fixed logic problem that arrose when using copy_to, copy_from and/or rename.
  • Loading branch information...
sudorandom committed May 2, 2012
1 parent f0b5a3a commit 3bb9e332132afd9b28e06f4fdf7e50896c475810
Showing with 26 additions and 14 deletions.
  1. +1 −1 object_storage/client.py
  2. +8 −4 object_storage/container.py
  3. +17 −9 object_storage/storage_object.py
View
@@ -83,7 +83,7 @@ def __init__(self, username=None,
self.model = None
- def load(self):
+ def load(self, cdn=True):
""" load data for the account
@return: object_storage.client, self
@@ -212,20 +212,24 @@ def objects(self, limit=None, marker=None, base_only=False, headers=None):
"""
params = {'format': 'json'}
if base_only:
- params['delimiter'] = '/'
+ params['delimiter'] = self.client.delimiter
if limit:
params['limit'] = limit
if marker:
params['marker'] = marker
def _formatter(res):
- objects = []
+ objects = {}
if res.content:
items = json.loads(res.content)
for item in items:
if 'name' in item:
- objects.append(self.storage_object(item['name'], item))
- return objects
+ objects[item['name']] = self.storage_object(item['name'], item)
+ elif 'subdir' in item:
+ item['name'] = item['subdir'].rstrip('/')
+ item['content_type'] = 'application/directory'
+ objects[item['name']] = self.storage_object(item['name'], item)
+ return objects.values()
return self.make_request('GET', params=params, headers=headers, formatter=_formatter)
def set_ttl(self, ttl):
@@ -145,7 +145,7 @@ def path(self):
path = [self.container, self.name]
return get_path(path)
- def list(self, limit=None, marker=None):
+ def list(self, limit=None, marker=None, base_only=False):
""" Uses sudo-hierarchical structure to list the children objects.
@param limit: limit of results to return.
@@ -155,20 +155,24 @@ def list(self, limit=None, marker=None):
"""
params = {'format': 'json',
'path': self.name}
+ if base_only:
+ params['delimiter'] = self.client.delimiter
if limit:
params['limit'] = limit
if marker:
params['marker'] = marker
def _formatter(res):
- objects = []
+ objects = {}
if res.content:
items = json.loads(res.content)
for item in items:
- obj = self.client.storage_object(self.container,
- item['name'],
- headers=item)
- objects.append(obj)
- return objects
+ if 'name' in item:
+ objects[item['name']] = self.client.storage_object(self.container, item['name'], headers=item)
+ elif 'subdir' in item:
+ item['name'] = item['subdir'].rstrip('/')
+ item['content_type'] = 'application/directory'
+ objects[item['name']] = self.client.storage_object(self.container, item['name'], headers=item)
+ return objects.values()
return self.client.make_request('GET', [self.container], params=params, formatter=_formatter)
def is_dir(self):
@@ -343,7 +347,9 @@ def copy_from(self, old_obj, *args, **kwargs):
headers = {}
headers['X-Copy-From'] = old_obj.path
headers['Content-Length'] = "0"
- return self.make_request('PUT', headers=headers, *args, formatter=lambda r: self, **kwargs)
+ if 'formatter' not in kwargs:
+ kwargs['formatter'] = lambda r: new_obj
+ return self.make_request('PUT', headers=headers, *args, **kwargs)
def copy_to(self, new_obj, *args, **kwargs):
""" Copies content from an existing object
@@ -355,7 +361,9 @@ def copy_to(self, new_obj, *args, **kwargs):
headers = {}
headers['Destination'] = new_obj.path
headers['Content-Length'] = "0"
- return self.make_request('COPY', headers=headers, *args, formatter=lambda r: new_obj, **kwargs)
+ if 'formatter' not in kwargs:
+ kwargs['formatter'] = lambda r: new_obj
+ return self.make_request('COPY', headers=headers, *args, **kwargs)
def rename(self, new_obj, *args, **kwargs):
""" Copies content to a new object existing object and deletes the current object

0 comments on commit 3bb9e33

Please sign in to comment.