def _parse_digital_forms(self, prop=DIGITAL_FORMS): """ Concatenates a list of Digital Form data structures parsed from the metadata """ xpath_map = self._data_structures[prop] # Parse base digital form fields: 'name', 'content', 'decompression', 'version', 'specification' xpath_root = self._data_map['_digital_forms_root'] digital_forms = parse_complex_list(self._xml_tree, xpath_root, xpath_map, prop) # Parse digital form transfer option fields: 'access_desc', 'access_instrs', 'network_resource' xpath_root = self._data_map['_transfer_options_root'] transfer_opts = parse_complex_list(self._xml_tree, xpath_root, xpath_map, prop) # Combine digital forms and transfer options into a single complex struct df_len = len(digital_forms) to_len = len(transfer_opts) parsed_forms = [] for idx in xrange(0, max(df_len, to_len)): digital_form = {}.fromkeys(_agis_definitions[prop], u'') if idx < df_len: digital_form.update(i for i in digital_forms[idx].items() if i[1]) if idx < to_len: digital_form.update(i for i in transfer_opts[idx].items() if i[1]) if any(digital_form.values()): parsed_forms.append(digital_form) return get_default_for_complex(prop, parsed_forms)
def _parse_digital_forms(self, prop=DIGITAL_FORMS): """ Concatenates a list of Digital Form data structures parsed from the metadata """ xpath_map = self._data_structures[prop] # Parse base digital form fields: 'name', 'content', 'decompression', 'version', 'specification' xpath_root = self._data_map['_digital_forms_root'] digital_forms = parse_complex_list(self._xml_tree, xpath_root, xpath_map, prop) # Parse digital form transfer option fields: 'access_desc', 'access_instrs', 'network_resource' xpath_root = self._data_map['_transfer_options_root'] transfer_opts = parse_complex_list(self._xml_tree, xpath_root, xpath_map, prop) # Split out digital form content that has been appended to specifications content_delim = _DIGITAL_FORMS_CONTENT_DELIM for digital_form in digital_forms: specs = reduce_value(digital_form['specification']) specs = specs.splitlines() if isinstance(specs, string_types) else specs specifications = wrap_value(s.strip() for s in specs) digital_form['content'] = [] digital_form['specification'] = [] has_content = False # For each specification, insert delim before appending content for spec in specifications: has_content = has_content or spec == content_delim if not has_content: digital_form['specification'].append(spec) elif spec != content_delim: digital_form['content'].append(spec) # Reduce spec and content to single string values if possible for form_prop in ('content', 'specification'): digital_form[form_prop] = reduce_value(filter_empty(digital_form[form_prop], u'')) # Combine digital forms and transfer options into a single complex struct df_len = len(digital_forms) to_len = len(transfer_opts) parsed_forms = [] for idx in xrange(0, max(df_len, to_len)): digital_form = {}.fromkeys(_iso_definitions[prop], u'') if idx < df_len: digital_form.update(i for i in digital_forms[idx].items() if i[1]) if idx < to_len: digital_form.update(i for i in transfer_opts[idx].items() if i[1]) if any(digital_form.values()): parsed_forms.append(digital_form) return get_default_for_complex(prop, parsed_forms)
def _parse_raster_info(self, prop=RASTER_INFO): """ Collapses multiple dimensions into a single raster_info complex struct """ raster_info = {}.fromkeys(_iso_definitions[prop], u'') # Ensure conversion of lists to newlines is in place raster_info['dimensions'] = get_default_for_complex_sub( prop=prop, subprop='dimensions', value=parse_property(self._xml_tree, None, self._data_map, '_ri_num_dims'), xpath=self._data_map['_ri_num_dims'] ) xpath_root = self._get_xroot_for(prop) xpath_map = self._data_structures[prop] for dimension in parse_complex_list(self._xml_tree, xpath_root, xpath_map, RASTER_DIMS): dimension_type = dimension['type'].lower() if dimension_type == 'vertical': raster_info['vertical_count'] = dimension['size'] elif dimension_type == 'column': raster_info['column_count'] = dimension['size'] raster_info['x_resolution'] = u' '.join(dimension[k] for k in ['value', 'units']).strip() elif dimension_type == 'row': raster_info['row_count'] = dimension['size'] raster_info['y_resolution'] = u' '.join(dimension[k] for k in ['value', 'units']).strip() return raster_info if any(raster_info[k] for k in raster_info) else {}
def _parse_complex_list(self, prop): """ Default parsing operation for lists of complex structs """ xpath_root = self._get_xroot_for(prop) xpath_map = self._data_structures[prop] return parse_complex_list(self._xml_tree, xpath_root, xpath_map, prop)
def _parse_attribute_details_file(self, prop=ATTRIBUTES): """ Concatenates a list of Attribute Details data structures parsed from a remote file """ # Parse content from remote file URL, which may be stored in one of two places: # Starting at: contentInfo/MD_FeatureCatalogueDescription/featureCatalogueCitation # ATTRIBUTE: href # ELEMENT TEXT: CI_Citation/.../CI_Contact/onlineResource/CI_OnlineResource/linkage self._attr_details_file_url = parse_property( self._xml_tree, None, self._data_map, '_attributes_file' ) if not self._attr_details_file_url: return None try: tree_to_parse = get_remote_element(self._attr_details_file_url) except Exception: self._attr_details_file_url = None return None xpath_map = self._data_structures[ATTRIBUTES] xpath_root = self._get_xroot_for(prop) return parse_complex_list(tree_to_parse, xpath_root, xpath_map, prop)
def _parse_attribute_details_file(self, prop=ATTRIBUTES): """ Concatenates a list of Attribute Details data structures parsed from a remote file """ # Parse content from remote file URL, which may be stored in one of two places: # Starting at: contentInfo/MD_FeatureCatalogueDescription/featureCatalogueCitation # ATTRIBUTE: href # ELEMENT TEXT: CI_Citation/.../CI_Contact/onlineResource/CI_OnlineResource/linkage self._attr_details_file_url = parse_property( self._xml_tree, None, self._data_map, '_attributes_file' ) if not self._attr_details_file_url: return None try: tree_to_parse = get_remote_element(self._attr_details_file_url) except: self._attr_details_file_url = None return None xpath_map = self._data_structures[ATTRIBUTES] xpath_root = self._get_xroot_for(prop) return parse_complex_list(tree_to_parse, xpath_root, xpath_map, prop)