Structurize DMI records into a nice list
    Optionally trash bogus entries and filter output

def _dmi_parse(data, clean=True, fields=None):
    '''
    Structurize DMI records into a nice list
    Optionally trash bogus entries and filter output
    '''
    dmi = []

    # Detect & split Handle records
    dmi_split = re.compile('(handle [0-9]x[0-9a-f]+[^\n]+)\n', re.MULTILINE+re.IGNORECASE)
    dmi_raw = iter(re.split(dmi_split, data)[1:])
    for handle, dmi_raw in zip(dmi_raw, dmi_raw):
        handle, htype = [hline.split()[-1] for hline in handle.split(',')][0:2]
        dmi_raw = dmi_raw.split('\n')
        # log.debug('%s record contains %s', handle, dmi_raw)
        log.debug('Parsing handle %s', handle)

        # The first line of a handle is a description of the type
        record = {
            'handle':      handle,
            'description': dmi_raw.pop(0).strip(),
            'type':        int(htype)
        }

        if not dmi_raw:
            # empty record
            if not clean:
                dmi.append(record)
            continue

        # log.debug('%s record contains %s', record, dmi_raw)
        dmi_data = _dmi_data(dmi_raw, clean, fields)
        if dmi_data:
            record['data'] = dmi_data
            dmi.append(record)
        elif not clean:
            dmi.append(record)

    return dmi