#NEWLINE# def negotiate_encoder( accept = None , encoders = None ) : #NEWLINE# #INDENT# "\n    Given the value of a 'Accept' header, return a two tuple of the appropriate\n    content type and codec registered to encode the response content.\n    " #NEWLINE# if ( encoders is None ) : #NEWLINE# #INDENT# encoders = default_encoders #NEWLINE# #UNINDENT# if ( accept is None ) : #NEWLINE# #INDENT# return codec [ 0 ] #NEWLINE# #UNINDENT# acceptable = set ( [ item . split ( ';' ) [ 0 ] . strip ( ) . lower ( ) for item in accept . split ( ',' ) ] ) #NEWLINE# for codec in encoders : #NEWLINE# #INDENT# if ( codec . media_type in acceptable ) : #NEWLINE# #INDENT# return codec #NEWLINE# #UNINDENT# #UNINDENT# for codec in encoders : #NEWLINE# #INDENT# if ( ( codec . media_type . split ( '/' ) [ 0 ] + '/*' ) in acceptable ) : #NEWLINE# #INDENT# return codec #NEWLINE# #UNINDENT# #UNINDENT# if ( '*/*' in acceptable ) : #NEWLINE# #INDENT# return encoders [ 0 ] #NEWLINE# #UNINDENT# msg = ( "Unsupported media in Accept header '%s'" % accept ) #NEWLINE# raise NotAcceptable ( msg )