def _dmi_parse(data, clean=True, fields=None):
 dmi = []
 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('Parsing handle {0}'.format(handle))
  record = {'handle': handle, 'description': dmi_raw.pop(0).strip(), 'type': int(htype)}
  if (not len(dmi_raw)):
   if (not clean):
    dmi.append(record)
   continue
  dmi_data = _dmi_data(dmi_raw, clean, fields)
  if len(dmi_data):
   record['data'] = dmi_data
   dmi.append(record)
  elif (not clean):
   dmi.append(record)
 return dmi

def _dmi_parse ( data , clean = True , fields = None ) : dmi = [ ] 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 ( 'Parsing handle {0}' . format ( handle ) ) record = { 'handle' : handle , 'description' : dmi_raw . pop ( 0 ) . strip ( ) , 'type' : int ( htype ) } if ( not len ( dmi_raw ) ) : if ( not clean ) : dmi . append ( record ) continue dmi_data = _dmi_data ( dmi_raw , clean , fields ) if len ( dmi_data ) : record [ 'data' ] = dmi_data dmi . append ( record ) elif ( not clean ) : dmi . append ( record ) return dmi
structurize dmi records into a nice list optionally trash bogus entries and filter output .