def parse(fn, out = None): """ Reads XML from the file name or object 'fn' and returns a 'Unit' instance. Rewrites the XML to out, if not None. """ e = etree.parse(fn).getroot() u = unit.Unit() u.lang = e.get('language') u.filename = e.get('filename') if out: open(out + os.path.basename(u.filename) + '.lh', 'w').write(etree.tostring(e)) u.source = e.find('raw-source').text for t in e.find('referenced-types').getchildren(): tt = types.aggregate_from_xml(t) assert tt.id not in u.types u.types[tt.id] = tt for f in e.find('function-bodies').getchildren(): u.functions += [ functions.Function.from_xml(f) ] u.finalise() return u
def __init__(self, type, value): self.type = types.aggregate_from_xml(type) self.value = value.text.decode('string-escape')