Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit 3bb9e332132afd9b28e06f4fdf7e50896c475810 1 parent f0b5a3a
@sudorandom sudorandom authored
View
2  object_storage/client.py
@@ -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
View
12 object_storage/container.py
@@ -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):
View
26 object_storage/storage_object.py
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.