safe.metadata.utils module

InaSAFE Disaster risk assessment tool developed by AusAid - metadata module.

Contact : ole.moller.nielsen@gmail.com

New in version 3.2.

Note

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

safe.metadata.utils.insert_xml_element(root, element_path)[source]

insert an XML element in an other creating the needed parents. :param root: The container :type root: ElementTree.Element :param element_path: The path relative to root :type element_path: str :return: ElementTree.Element :rtype : ElementTree.Element

safe.metadata.utils.merge_dictionaries(base_dict, extra_dict)[source]

merge two dictionaries.

if both have a same key, the one from extra_dict is taken

Parameters:
  • base_dict (dict) – first dictionary
  • extra_dict (dict) – second dictionary
Returns:

a merge of the two dictionaries

Return type:

dicts

safe.metadata.utils.prettify_xml(xml_str)[source]

returns prettified XML without blank lines

based on http://stackoverflow.com/questions/14479656/ :param xml_str: the XML to be prettified :type xml_str: str :return: the prettified XML :rtype: str

safe.metadata.utils.read_property_from_xml(root, path)[source]

Get the text from an XML property.

Whitespaces, tabs and new lines are trimmed

Parameters:
  • root (ElementTree.Element) – container in which we search
  • path (str) – path to search in root
Returns:

the text of the element at the given path

Return type:

str, None

safe.metadata.utils.reading_ancillary_files(*args, **kwds)[source]

context manager to be used when reading metadata so no errors are risen.

This is useful because we want to be able to get as much as possible out of malformed input

Parameters:metadata (BaseMetadata) – the metadata object