<s> from __future__ import unicode_literals <EOL> import mimeparse <EOL> from tastypie . exceptions import BadRequest <EOL> def determine_format ( request , serializer , default_format = '<STR_LIT:application/json>' ) : <EOL> """<STR_LIT>""" <EOL> format = request . GET . get ( '<STR_LIT>' ) <EOL> if format : <EOL> if format in serializer . formats : <EOL> return serializer . get_mime_for_format ( format ) <EOL> if '<STR_LIT>' in request . GET : <EOL> return serializer . get_mime_for_format ( '<STR_LIT>' ) <EOL> accept = request . META . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if accept != '<STR_LIT>' : <EOL> try : <EOL> best_format = mimeparse . best_match ( serializer . supported_formats_reversed , accept ) <EOL> except ValueError : <EOL> raise BadRequest ( '<STR_LIT>' ) <EOL> if best_format : <EOL> return best_format <EOL> return default_format <EOL> def build_content_type ( format , encoding = '<STR_LIT:utf-8>' ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in format : <EOL> return format <EOL> if format in ( '<STR_LIT:application/json>' , '<STR_LIT>' ) : <EOL> return format <EOL> return "<STR_LIT>" % ( format , encoding ) </s>
