def format(file_metrics, build_metrics):
def indent(elem, level=<NUM_LIT:0>):<EOL><INDENT>i = "<STR_LIT:\n>" + level*"<STR_LIT:U+0020>"<EOL>if len(elem):<EOL><INDENT>if not elem.text or not elem.text.strip():<EOL><INDENT>elem.text = i + "<STR_LIT:U+0020>"<EOL><DEDENT>if not elem.tail or not elem.tail.strip():<EOL><INDENT>elem.tail = i<EOL><DEDENT>for elem in elem:<EOL><INDENT>indent(elem, level+<NUM_LIT:1>)<EOL><DEDENT>if not elem.tail or not elem.tail.strip():<EOL><INDENT>elem.tail = i<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if level and (not elem.tail or not elem.tail.strip()):<EOL><INDENT>elem.tail = i<EOL><DEDENT><DEDENT><DEDENT>root = ET.Element('<STR_LIT>')<EOL>files = ET.Element('<STR_LIT>')<EOL>root.append(files)<EOL>for key in file_metrics.keys():<EOL><INDENT>tmp_file = ET.SubElement(files, "<STR_LIT:file>",<EOL>{'<STR_LIT:name>': key, '<STR_LIT>': file_metrics[key]['<STR_LIT>']})<EOL>for name in file_metrics[key].keys():<EOL><INDENT>if name == '<STR_LIT>':<EOL><INDENT>continue<EOL><DEDENT>tmp_metric = ET.SubElement(tmp_file, "<STR_LIT>",<EOL>{'<STR_LIT:name>': name, '<STR_LIT:value>': str(file_metrics[key][name])})<EOL><DEDENT><DEDENT>if build_metrics:<EOL><INDENT>build = ET.Element('<STR_LIT>')<EOL>root.append(build)<EOL><DEDENT>indent(root)<EOL>if PY3:<EOL><INDENT>body = ET.tostring(root, encoding='<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>body = ET.tostring(root)<EOL><DEDENT>return body<EOL>
compute output in XML format.