#NEWLINE# def _encode_data( self , data , format = None , content_type = None ) : #NEWLINE# #INDENT# '\n        Encode the data returning a two tuple of (bytes, content_type)\n        ' #NEWLINE# if ( data is None ) : #NEWLINE# #INDENT# return ( '' , content_type ) #NEWLINE# #UNINDENT# assert ( ( format is None ) or ( content_type is None ) ) , 'You may not set both `format` and `content_type`.' #NEWLINE# if content_type : #NEWLINE# #INDENT# ret = force_bytes ( data , settings . DEFAULT_CHARSET ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# format = ( format or self . default_format ) #NEWLINE# assert ( format in self . renderer_classes ) , "Invalid format '{0}'. Available formats are {1}. Set TEST_REQUEST_RENDERER_CLASSES to enable extra request formats." . format ( format , ', ' . join ( [ ( ( "'" + fmt ) + "'" ) for fmt in self . renderer_classes . keys ( ) ] ) ) #NEWLINE# renderer = self . renderer_classes [ format ] ( ) #NEWLINE# ret = renderer . render ( data ) #NEWLINE# content_type = '{0}; charset={1}' . format ( renderer . media_type , renderer . charset ) #NEWLINE# if isinstance ( data , six . text_type ) : #NEWLINE# #INDENT# ret = bytes ( ret . encode ( renderer . charset ) ) #NEWLINE# #UNINDENT# #UNINDENT# return ( ret , content_type )