Skip to content
This repository has been archived by the owner on Aug 20, 2022. It is now read-only.

Commit

Permalink
Bug Fixes
Browse files Browse the repository at this point in the history
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 3bb9e33
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion object_storage/client.py
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions object_storage/container.py
Expand Up @@ -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):
Expand Down
26 changes: 17 additions & 9 deletions object_storage/storage_object.py
Expand Up @@ -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.
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 3bb9e33

Please sign in to comment.