def cpe2dict(cpe_str):
 if (not cpe_str.startswith('cpe:/')):
  raise ValueError(('invalid cpe format (%s)\n' % cpe_str))
 cpe_body = cpe_str[5:]
 parts = cpe_body.split(':', 3)
 nparts = len(parts)
 if (nparts < 2):
  raise ValueError(('invalid cpe format (%s)\n' % cpe_str))
 cpe_type = parts[0]
 cpe_vend = parts[1]
 cpe_prod = (parts[2] if (nparts > 2) else '')
 cpe_vers = (parts[3] if (nparts > 3) else '')
 ret = {'type': cpe_type, 'vendor': cpe_vend, 'product': cpe_prod, 'version': cpe_vers}
 return ret

def cpe2dict ( cpe_str ) : if ( not cpe_str . startswith ( 'cpe:/' ) ) : raise ValueError ( ( 'invalid cpe format (%s)\n' % cpe_str ) ) cpe_body = cpe_str [ 5 : ] parts = cpe_body . split ( ':' , 3 ) nparts = len ( parts ) if ( nparts < 2 ) : raise ValueError ( ( 'invalid cpe format (%s)\n' % cpe_str ) ) cpe_type = parts [ 0 ] cpe_vend = parts [ 1 ] cpe_prod = ( parts [ 2 ] if ( nparts > 2 ) else '' ) cpe_vers = ( parts [ 3 ] if ( nparts > 3 ) else '' ) ret = { 'type' : cpe_type , 'vendor' : cpe_vend , 'product' : cpe_prod , 'version' : cpe_vers } return ret
helper function to parse cpes .