def _encode_data(self, data, format=None, content_type=None):
if not data:<EOL><INDENT>return ('<STR_LIT>', None)<EOL><DEDENT>assert format is None or content_type is None, (<EOL>'<STR_LIT>'<EOL>)<EOL>if content_type:<EOL><INDENT>ret = force_bytes(data, settings.DEFAULT_CHARSET)<EOL><DEDENT>else:<EOL><INDENT>format = format or self.default_format<EOL>assert format in self.renderer_classes, (<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(<EOL>format,<EOL>'<STR_LIT:U+002CU+0020>'.join(<EOL>["<STR_LIT:'>" + fmt + "<STR_LIT:'>" for fmt in self.renderer_classes.keys()])<EOL>)<EOL>)<EOL>renderer = self.renderer_classes[format]()<EOL>ret = renderer.render(data)<EOL>content_type = "<STR_LIT>".format(<EOL>renderer.media_type, renderer.charset<EOL>)<EOL>if isinstance(ret, six.text_type):<EOL><INDENT>ret = bytes(ret.encode(renderer.charset))<EOL><DEDENT><DEDENT>return ret, content_type<EOL>
Encode the data returning a two tuple of (bytes, content_type)