Format the data.

        In derived classes, it is usually better idea to override
        ``_format_data()`` than this method.

        :param response: devil's ``Response`` object or the data
                         itself. May also be ``None``.
        :return: django's ``HttpResponse``

        todo: this shouldn't change the given response. only return the
        formatted response.

def format(self, response):
        """ Format the data.

        In derived classes, it is usually better idea to override
        ``_format_data()`` than this method.

        :param response: devil's ``Response`` object or the data
                         itself. May also be ``None``.
        :return: django's ``HttpResponse``

        todo: this shouldn't change the given response. only return the
        formatted response.
        """

        res = self._prepare_response(response)
        res.content = self._format_data(res.content, self.charset)
        return self._finalize_response(res)