'Writes this response using WSGI semantics with the given WSGI function.
Args:
start_response: the WSGI-compatible start_response function'

def wsgi_write(self, start_response):

    body = self.out.getvalue()
    if isinstance(body, unicode):
        body = body.encode('utf-8')
    elif self.headers.get('Content-Type', '').endswith(';    charset=utf-8'):
        try:
            body.decode('utf-8')
        except UnicodeError as e:
            logging.warning('Response    written    is    not    UTF-8:    %s', e)
    if ((self.headers.get('Cache-Control') == 'no-cache') and (not self.headers.get('Expires'))):
        self.headers['Expires'] = 'Mon,    01    Jan    1990    00:00:00    GMT'
    self.headers['Content-Length'] = str(len(body))
    new_headers = []
    for (header, value) in self.__wsgi_headers:
        if (not isinstance(value, basestring)):
            value = unicode(value)
        if (('\n' in header) or ('\r' in header) or ('\n' in value) or ('\r' in value)):
            logging.warning('Replacing    newline    in    header:    %s', repr((header, value)))
            value = value.replace('\n', '').replace('\r', '')
            header = header.replace('\n', '').replace('\r', '')
        new_headers.append((header, value))
    self.__wsgi_headers = new_headers
    write = start_response(('%d    %s' % self.__status), self.__wsgi_headers)
    write(body)
    self.out.close()
