#NEWLINE# def best_match( supported , header ) : #NEWLINE# #INDENT# "Takes a list of supported mime-types and finds the best\n    match for all the media-ranges listed in header. The value of\n    header must be a string that conforms to the format of the \n    HTTP Accept: header. The value of 'supported' is a list of\n    mime-types. The list of supported mime-types should be sorted\n    in order of increasing desirability, in case of a situation \n    where there is a tie\n    \n    >>> best_match(['application/xbel+xml', 'text/xml'], 'text/*;q=0.5,*/*; q=0.1')\n    'text/xml'\n    " #NEWLINE# parsed_header = [ parse_media_range ( r ) for r in _filter_blank ( header . split ( ',' ) ) ] #NEWLINE# weighted_matches = [ ] #NEWLINE# pos = 0 #NEWLINE# for mime_type in supported : #NEWLINE# #INDENT# weighted_matches . append ( ( fitness_and_quality_parsed ( mime_type , parsed_header ) , pos , mime_type ) ) #NEWLINE# pos += 1 #NEWLINE# #UNINDENT# weighted_matches . sort ( ) #NEWLINE# return ( ( parsed_header [ ( - 1 ) ] [ 0 ] [ 1 ] and weighted_matches [ ( - 1 ) ] [ 2 ] ) or '' )