def create_listing(self, req, out_content_type, info, resp_headers, metadata, container_list, container): for key, (value, _timestamp) in metadata.items(): if value and (key.lower() in self.save_headers or is_sys_or_user_meta('container', key)): resp_headers[str_to_wsgi(key)] = str_to_wsgi(value) listing = [ self.update_data_record(record) for record in container_list ] if out_content_type.endswith('/xml'): body = listing_formats.container_to_xml(listing, container) elif out_content_type.endswith('/json'): body = json.dumps(listing).encode('ascii') else: body = listing_formats.listing_to_text(listing) ret = Response(request=req, headers=resp_headers, body=body, content_type=out_content_type, charset='utf-8') ret.last_modified = math.ceil(float(resp_headers['X-PUT-Timestamp'])) if not ret.body: ret.status_int = HTTP_NO_CONTENT return ret
def account_listing_response(account, req, response_content_type, broker=None, limit='', marker='', end_marker='', prefix='', delimiter='', reverse=False): if broker is None: broker = FakeAccountBroker() resp_headers = get_response_headers(broker) account_list = broker.list_containers_iter(limit, marker, end_marker, prefix, delimiter, reverse) data = [] for (name, object_count, bytes_used, put_timestamp, is_subdir) \ in account_list: name_ = name.decode('utf8') if six.PY2 else name if is_subdir: data.append({'subdir': name_}) else: data.append( {'name': name_, 'count': object_count, 'bytes': bytes_used, 'last_modified': Timestamp(put_timestamp).isoformat}) if response_content_type.endswith('/xml'): account_list = listing_formats.account_to_xml(data, account) ret = HTTPOk(body=account_list, request=req, headers=resp_headers) elif response_content_type.endswith('/json'): account_list = json.dumps(data).encode('ascii') ret = HTTPOk(body=account_list, request=req, headers=resp_headers) elif data: account_list = listing_formats.listing_to_text(data) ret = HTTPOk(body=account_list, request=req, headers=resp_headers) else: ret = HTTPNoContent(request=req, headers=resp_headers) ret.content_type = response_content_type ret.charset = 'utf-8' return ret
def account_listing_response(account, req, response_content_type, broker=None, limit=constraints.ACCOUNT_LISTING_LIMIT, marker='', end_marker='', prefix='', delimiter='', reverse=False): if broker is None: broker = FakeAccountBroker() resp_headers = get_response_headers(broker) account_list = broker.list_containers_iter(limit, marker, end_marker, prefix, delimiter, reverse, req.allow_reserved_names) data = [] for (name, object_count, bytes_used, put_timestamp, is_subdir) \ in account_list: name_ = name.decode('utf8') if six.PY2 else name if is_subdir: data.append({'subdir': name_}) else: data.append({ 'name': name_, 'count': object_count, 'bytes': bytes_used, 'last_modified': Timestamp(put_timestamp).isoformat }) if response_content_type.endswith('/xml'): account_list = listing_formats.account_to_xml(data, account) ret = HTTPOk(body=account_list, request=req, headers=resp_headers) elif response_content_type.endswith('/json'): account_list = json.dumps(data).encode('ascii') ret = HTTPOk(body=account_list, request=req, headers=resp_headers) elif data: account_list = listing_formats.listing_to_text(data) ret = HTTPOk(body=account_list, request=req, headers=resp_headers) else: ret = HTTPNoContent(request=req, headers=resp_headers) ret.content_type = response_content_type ret.charset = 'utf-8' return ret
def create_listing(self, req, out_content_type, info, resp_headers, metadata, container_list, container): for key, (value, timestamp) in metadata.items(): if value and (key.lower() in self.save_headers or is_sys_or_user_meta('container', key)): resp_headers[str_to_wsgi(key)] = str_to_wsgi(value) listing = [self.update_data_record(record) for record in container_list] if out_content_type.endswith('/xml'): body = listing_formats.container_to_xml(listing, container) elif out_content_type.endswith('/json'): body = json.dumps(listing).encode('ascii') else: body = listing_formats.listing_to_text(listing) ret = Response(request=req, headers=resp_headers, body=body, content_type=out_content_type, charset='utf-8') ret.last_modified = math.ceil(float(resp_headers['X-PUT-Timestamp'])) if not ret.body: ret.status_int = HTTP_NO_CONTENT return ret