def __call__(self, *args, **kwargs):
        """Set up encoding for the HTTP response."""
        response = cherrypy.serving.response
        self.body = self.oldhandler(*args, **kwargs)

        self.body = prepare_iter(self.body)

        ct = response.headers.elements('Content-Type')
        if self.debug:
            cherrypy.log(
                'Content-Type: %r' % [str(h) for h in ct],
                'TOOLS.ENCODE',
            )
        if ct and self.add_charset:
            ct = ct[0]
            if self.text_only:
                if ct.value.lower().startswith('text/'):
                    if self.debug:
                        cherrypy.log(
                            'Content-Type %s starts with "text/"' % ct,
                            'TOOLS.ENCODE',
                        )
                    do_find = True
                else:
                    if self.debug:
                        cherrypy.log(
                            'Not finding because Content-Type %s '
                            'does not start with "text/"' % ct,
                            'TOOLS.ENCODE',
                        )
                    do_find = False
            else:
                if self.debug:
                    cherrypy.log(
                        'Finding because not text_only',
                        'TOOLS.ENCODE',
                    )
                do_find = True

            if do_find:
                # Set "charset=..." param on response Content-Type header
                ct.params['charset'] = self.find_acceptable_charset()
                if self.debug:
                    cherrypy.log(
                        'Setting Content-Type %s' % ct,
                        'TOOLS.ENCODE',
                    )
                response.headers['Content-Type'] = str(ct)

        return self.body
Set up encoding for the HTTP response.
cherrypy/lib/encoding.py