'Performs the actual WSGI dispatching for the application.'

def dispatch(self, environ, start_response):

    try:
        httprequest = werkzeug.wrappers.Request(environ)
        httprequest.app = self
        httprequest.parameter_storage_class = werkzeug.datastructures.ImmutableOrderedMultiDict
        threading.current_thread().url = httprequest.url
        explicit_session = self.setup_session(httprequest)
        self.setup_db(httprequest)
        self.setup_lang(httprequest)
        request = self.get_request(httprequest)
        def _dispatch_nodb():
            try:
                (func, arguments) = self.nodb_routing_map.bind_to_environ(request.httprequest.environ).match()
            except werkzeug.exceptions.HTTPException as e:
                return request._handle_exception(e)
            request.set_handler(func, arguments, 'none')
            result = request.dispatch()
            return result
        with request:
            db = request.session.db
            if db:
                try:
                    odoo.registry(db).check_signaling()
                    with odoo.tools.mute_logger('odoo.sql_db'):
                        ir_http = request.registry['ir.http']
                except (AttributeError, psycopg2.OperationalError, psycopg2.ProgrammingError):
                    request.session.logout()
                    if (request.httprequest.path == '/web'):
                        result = werkzeug.utils.redirect('/web/database/selector')
                    else:
                        result = _dispatch_nodb()
                else:
                    result = ir_http._dispatch()
                    ir_http.pool.signal_caches_change()
            else:
                result = _dispatch_nodb()
            response = self.get_response(httprequest, result, explicit_session)
        return response(environ, start_response)
    except werkzeug.exceptions.HTTPException as e:
        return e(environ, start_response)
