Small refactor on list uploads

The filter to drop the segments from object list is confusable
a bit because the filter result is assigned to the same name
(i.e. "objects") even though it is an upload id subset of the objects.

This patch refactors a bit to be the meaning more clear.

Change-Id: I73a49cca2e084cd13c8c10555e17351af8669af9
This commit is contained in:
Kota Tsuyuzaki
2015-03-15 20:18:35 -07:00
parent 07f2681876
commit 9e9598a02e

View File

@@ -141,13 +141,6 @@ class UploadsController(Controller):
"""
Handles List Multipart Uploads
"""
pattern = re.compile('/[0-9]+$')
def filter_max_uploads(o):
if 'name' not in o:
return False
else:
return pattern.search(o['name']) is None
encoding_type = req.params.get('encoding-type')
if encoding_type is not None and encoding_type != 'url':
@@ -177,23 +170,27 @@ class UploadsController(Controller):
resp = req.get_response(self.app, container=container, query=query)
objects = json.loads(resp.body)
objects = filter(filter_max_uploads, objects)
def object_to_upload(object_info):
obj, upid = object_info['name'].rsplit('/', 1)
obj_dict = {'key': obj,
'upload_id': upid,
'last_modified': object_info['last_modified']}
return obj_dict
if len(objects) > maxuploads:
objects = objects[:maxuploads]
# uploads is a list consists of dict, {key, upload_id, last_modified}
# Note that pattern matcher willd drop whole segments objects like as
# object_name/upload_id/1.
pattern = re.compile('/[0-9]+$')
uploads = [object_to_upload(obj) for obj in objects if
pattern.search(obj.get('name', '')) is None]
if len(uploads) > maxuploads:
uploads = uploads[:maxuploads]
truncated = True
else:
truncated = False
uploads = []
prefixes = []
for o in objects:
obj, upid = o['name'].rsplit('/', 1)
uploads.append(
{'key': obj,
'upload_id': upid,
'last_modified': o['last_modified']}
)
nextkeymarker = ''
nextuploadmarker = ''