def turbolinks(app):
    """Enable turbolinks.

    You don't need to do any configuration, wrap your app with turbolinks::

        app = Flask(__name__)
        app.secret_key = 'secret'
        turbolinks(app)

    And everything will be ready. Put turbolinks.js in the ``<head>`` of
    your html templates, it just works.
    """
    from flask import request, session

    app.wsgi_app = TurbolinksMiddleware(app.wsgi_app)

    @app.after_request
    def turbolinks_response(response):
        referrer = request.headers.get('X-XHR-Referer')
        if not referrer:
            # turbolinks not enabled
            return response

        method = request.cookies.get('request_method', None)
        if not method or method != request.method:
            response.set_cookie('request_method', request.method)

        if response.headers in 'Location':
            # this is a redirect response
            loc = response.headers['Location']
            session['_turbolinks_redirect_to'] = loc

            # cross domain redirect
            if referrer and not same_origin(loc, referrer):
                response.status_code = 200
                response.data = (
                    '<body><script>location.href="%s"</script></body>'
                ) % loc
        else:
            if '_turbolinks_redirect_to' in session:
                loc = session.pop('_turbolinks_redirect_to')
                response.headers['X-XHR-Redirected-To'] = loc
        return response

    return app
dataset/ETHPy150Open lepture/flask-turbolinks/flask_turbolinks.py/turbolinks/swapped operands of `in`