#NEWLINE# @ classmethod #NEWLINE# def resolve( self , accept , provide ) : #NEWLINE# #INDENT# '\n        Resolves a list of accepted MediaTypes and available renderers to the preferred renderer.\n\n        Call as MediaType.resolve([MediaType], [(MediaType, renderer)]).\n        ' #NEWLINE# if ( len ( accept ) == 0 ) : #NEWLINE# #INDENT# return [ ] #NEWLINE# #UNINDENT# accept . sort ( ) #NEWLINE# ( eq_classes , accept ) = ( [ [ accept [ ( - 1 ) ] ] ] , accept [ : ( - 1 ) ] ) #NEWLINE# while accept : #NEWLINE# #INDENT# imt = accept . pop ( ) #NEWLINE# if imt . equivalent ( eq_classes [ 0 ] [ ( - 1 ) ] ) : #NEWLINE# #INDENT# eq_classes [ ( - 1 ) ] . append ( imt ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# eq_classes . append ( [ imt ] ) #NEWLINE# #UNINDENT# #UNINDENT# ( renderers , seen_renderers ) = ( [ ] , set ( ) ) #NEWLINE# for imts in eq_classes : #NEWLINE# #INDENT# for ( provide_type , renderer ) in provide : #NEWLINE# #INDENT# for imt in imts : #NEWLINE# #INDENT# if ( ( renderer not in seen_renderers ) and provide_type . provides ( imt ) ) : #NEWLINE# #INDENT# renderers . append ( renderer ) #NEWLINE# seen_renderers . add ( renderer ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return provide