'Encode the data returning a two tuple of (bytes, content_type)'

def _encode_data(self, data, format=None, content_type=None):

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