'The bottle WSGI-interface.'

def wsgi(self, environ, start_response):

    try:
        environ['bottle.app'] = self
        request.bind(environ)
        response.bind()
        out = self._cast(self._handle(environ), request, response)
        if ((response.status_code in (100, 101, 204, 304)) or (request.method == 'HEAD')):
            if hasattr(out, 'close'):
                out.close()
            out = []
        start_response(response.status_line, list(response.iter_headers()))
        return out
    except (KeyboardInterrupt, SystemExit, MemoryError):
        raise
    except Exception as e:
        if (not self.catchall):
            raise
        err = ('<h1>Critical    error    while    processing    request:    %s</h1>' % environ.get('PATH_INFO', '/'))
        if DEBUG:
            err += ('<h2>Error:</h2>\n<pre>%s</pre>\n' % repr(e))
            err += ('<h2>Traceback:</h2>\n<pre>%s</pre>\n' % format_exc(10))
        environ['wsgi.errors'].write(err)
        start_response('500    INTERNAL    SERVER    ERROR', [('Content-Type', 'text/html')])
        return [tob(err)]
