def fitness_and_quality_parsed(mime_type, parsed_ranges):
 (best_fitness, best_fit_q) = ((-1), 0)
 (target_type, target_subtype, target_params) = parse_media_range(mime_type)
 for (type, subtype, params) in parsed_ranges:
  if (((type == target_type) or (type == '*') or (target_type == '*')) and ((subtype == target_subtype) or (subtype == '*') or (target_subtype == '*'))):
   fitness = 0
   if (type == target_type):
    fitness += 100
   if (subtype == target_subtype):
    fitness += 10
   for key in target_params:
    if ((key != 'q') and (key in params)):
     if (params[key] == target_params[key]):
      fitness += 1
   if (fitness > best_fitness):
    best_fitness = fitness
    best_fit_q = params['q']
 return (best_fitness, float(best_fit_q))

def fitness_and_quality_parsed ( mime_type , parsed_ranges ) : ( best_fitness , best_fit_q ) = ( ( - 1 ) , 0 ) ( target_type , target_subtype , target_params ) = parse_media_range ( mime_type ) for ( type , subtype , params ) in parsed_ranges : if ( ( ( type == target_type ) or ( type == '*' ) or ( target_type == '*' ) ) and ( ( subtype == target_subtype ) or ( subtype == '*' ) or ( target_subtype == '*' ) ) ) : fitness = 0 if ( type == target_type ) : fitness += 100 if ( subtype == target_subtype ) : fitness += 10 for key in target_params : if ( ( key != 'q' ) and ( key in params ) ) : if ( params [ key ] == target_params [ key ] ) : fitness += 1 if ( fitness > best_fitness ) : best_fitness = fitness best_fit_q = params [ 'q' ] return ( best_fitness , float ( best_fit_q ) )
find the best match for a given mime-type against a list of media_ranges that have already been parsed by parse_media_range() .