def from_result(cls, container, result): """Create from ambiguous result.""" if result is None: raise errors.NoObjectException elif cls.is_prefix(result): return cls.from_prefix(container, result) elif cls.is_key(result): return cls.from_key(container, result) raise errors.CloudException("Unknown boto result type: %s" % type(result))
def _get_object_infos(self, path, marker=None, limit=settings.CLOUD_BROWSER_DEFAULT_LIST_LIMIT): """Get raw object infos (single-shot).""" # Adjust limit to +1 to handle marker object as first result. # We can get in to this situation for a marker of "foo", that will # still return a 'subdir' object of "foo/" because of the extra # slash. orig_limit = limit limit += 1 # Enforce maximum object size. if limit > RS_MAX_LIST_OBJECTS_LIMIT: raise errors.CloudException("Object limit must be less than %s" % RS_MAX_LIST_OBJECTS_LIMIT) def _collapse(infos): """Remove duplicate dummy / implied objects.""" name = None for info in infos: name = info.get("name", name) subdir = info.get("subdir", "").strip(SEP) if not name or subdir != name: yield info path = path + SEP if path else "" object_infos = self.native_container.list_objects_info(limit=limit, delimiter=SEP, prefix=path, marker=marker) full_query = len(object_infos) == limit if object_infos: # Check first object for marker match and truncate if so. if marker and object_infos[0].get("subdir", "").strip(SEP) == marker: object_infos = object_infos[1:] # Collapse subdirs and dummy objects. object_infos = list(_collapse(object_infos)) # Adjust to original limit. if len(object_infos) > orig_limit: object_infos = object_infos[:orig_limit] return object_infos, full_query