def _process_metadata(self, headers): """ Get CDMI metadata from the header and add to the body """ metadata = {} for header, value in headers.iteritems(): key = header.lower() if key.startswith(self.metadata_prefix): key, value = get_pair_from_header(value) if key != '' and value != '': metadata[key] = value return metadata
def _read_container(self, env, start_response, headers, children): # Build the response message body according to CDMI specification res = Response() res.headers['content-type'] = 'application/json; charset=UTF-8' body = {} # Setup required attributes for response body body['objectType'] = Consts.CDMI_APP_CONTAINER if self.object_name: body['objectName'] = self.object_name + '/' body['parentURI'] = concat_parts(self.account_name, self.container_name, self.parent_name) + '/' else: body['objectName'] = self.container_name + '/' body['parentURI'] = self.account_name + '/' body['capabilitiesURI'] = concat_parts(self.cdmi_capability_id, self.account_name, self.container_name, self.parent_name, self.object_name) + '/' body['completionStatus'] = 'Complete' body['metadata'] = {} #Get CDMI metadata from the header and add to the body for header, value in headers.iteritems(): key = header.lower() if key.startswith(self.metadata_prefix): key, value = get_pair_from_header(value) if key != '' and value != '': body['metadata'][key] = value body['children'] = [] if children: string_to_cut = concat_parts(self.parent_name, self.object_name) size = len(string_to_cut) if size > 0: size += 1 tracking_device = {} for child in children: if child.get('name', False): child_name = child.get('name') else: child_name = child.get('subdir', False) if child_name: child_name = child_name[size:] if not child_name.endswith('/'): content_type = child.get('content_type', '') if content_type.find('directory') >= 0: child_name += '/' if tracking_device.get(child_name) is None: tracking_device[child_name] = child_name body['children'].append(child_name) res.body = json.dumps(body, indent=2) res.status_int = 200 return res