<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def _dmi_data(dmi_raw, clean, fields):
    '''
    Parse the raw DMIdecode output of a single handle
    into a nice dict
    '''
    dmi_data = {}

    key = None
    key_data = [None, []]
    for line in dmi_raw:
        if re.match(r'\t[^\s]+', line):
            # Finish previous key
            if key is not None:
                # log.debug('Evaluating DMI key {0}: {1}'.format(key, key_data))
                value, vlist = key_data
                if vlist:
                    if value is not None:
                        # On the rare occasion
                        # (I counted 1 on all systems we have)
                        # that there's both a value <and> a list
                        # just insert the value on top of the list
                        vlist.insert(0, value)
                    dmi_data[key] = vlist
                elif value is not None:
                    dmi_data[key] = value

            # Family: Core i5
            # Keyboard Password Status: Not Implemented
            key, val = line.split(':', 1)
            key = key.strip().lower().replace(' ', '_')
            if (clean and key == 'header_and_data') \
                    or (fields and key not in fields):
                key = None
                continue
            else:
                key_data = [_dmi_cast(key, val.strip(), clean), []]
        elif key is None:
            continue
        elif re.match(r'\t\t[^\s]+', line):
            # Installable Languages: 1
            #        en-US
            # Characteristics:
            #        PCI is supported
            #        PNP is supported
            val = _dmi_cast(key, line.strip(), clean)
            if val is not None:
                # log.debug('DMI key %s gained list item %s', key, val)
                key_data[1].append(val)

    return dmi_data