Beispiel #1
0
 def my_url_for(self, endpoint, **values):
     try:
         # RequestContext.push() causes wrong context to be popped when app
         # preserves context on exception, the default for app.debug=True.
         # Instead, push/pop directly on the LocalStack.
         _request_ctx_stack.push(self.invitation_context)
         return url_for(endpoint, **values)
     finally:
         _request_ctx_stack.pop()
Beispiel #2
0
def main():
    if len(sys.argv) < 3:
        complain_usage()

    _request_ctx_stack.push(1)
    db.create_all()
    if sys.argv[1] == "images":
        migrate_images(sys.argv[2])
    elif sys.argv[1] == "instances":
        migrate_instances(sys.argv[2])
    else:
        complain_usage()
Beispiel #3
0
def main():
    if len(sys.argv) < 3:
        complain_usage()

    _request_ctx_stack.push(1)
    db.create_all()
    if sys.argv[1] == "images":
        migrate_images(sys.argv[2])
    elif sys.argv[1] == "instances":
        migrate_instances(sys.argv[2])
    else:
        complain_usage()
Beispiel #4
0
    def push(self):
        #top = _request_ctx_stack.top
         #   top.pop(top._preserved_exc)
        app_ctx = _app_ctx_stack.top
        if app_ctx is None or app_ctx.app != self.app:  #判斷
            app_ctx = self.app.app_context()
            app_ctx.push()
            self._implicit_app_ctx_stack.append(app_ctx)  #棧裏放入
        else:
            self._implicit_app_ctx_stack.append(None)

        _request_ctx_stack.push(self)
Beispiel #5
0
def test_recordsearchv2_with_preference_param_no_request_no_param(app):
    # WARNING: the app fixture *somehow* pushes a request context
    #          even though it should not. We pop it and push it back later.
    if _request_ctx_stack.top:
        prior_request_ctx = _request_ctx_stack.pop()

    assert has_request_context() is False

    search = SpySearchV2().with_preference_param()

    assert {} == search.exposed_params

    _request_ctx_stack.push(prior_request_ctx)
Beispiel #6
0
    def session_transaction(self, *args, **kwargs):
        """When used in combination with a ``with`` statement this opens a
        session transaction.  This can be used to modify the session that
        the test client uses.  Once the ``with`` block is left the session is
        stored back.

        ::

            with client.session_transaction() as session:
                session['value'] = 42

        Internally this is implemented by going through a temporary test
        request context and since session handling could depend on
        request variables this function accepts the same arguments as
        :meth:`~flask.Flask.test_request_context` which are directly
        passed through.
        """
        if self.cookie_jar is None:
            raise RuntimeError(
                "Session transactions only make sense " "with cookies enabled."
            )
        app = self.application
        environ_overrides = kwargs.setdefault("environ_overrides", {})
        self.cookie_jar.inject_wsgi(environ_overrides)
        outer_reqctx = _request_ctx_stack.top
        with app.test_request_context(*args, **kwargs) as c:
            session_interface = app.session_interface
            sess = session_interface.open_session(app, c.request)
            if sess is None:
                raise RuntimeError(
                    "Session backend did not open a session. " "Check the configuration"
                )

            # Since we have to open a new request context for the session
            # handling we want to make sure that we hide out own context
            # from the caller.  By pushing the original request context
            # (or None) on top of this and popping it we get exactly that
            # behavior.  It's important to not use the push and pop
            # methods of the actual request context object since that would
            # mean that cleanup handlers are called
            _request_ctx_stack.push(outer_reqctx)
            try:
                yield sess
            finally:
                _request_ctx_stack.pop()

            resp = app.response_class()
            if not session_interface.is_null_session(sess):
                session_interface.save_session(app, sess, resp)
            headers = resp.get_wsgi_headers(c.request.environ)
            self.cookie_jar.extract_wsgi(c.request.environ, headers)
    def session_transaction(self, *args, **kwargs):
        """When used in combination with a ``with`` statement this opens a
        session transaction.  This can be used to modify the session that
        the test client uses.  Once the ``with`` block is left the session is
        stored back.

        ::

            with client.session_transaction() as session:
                session['value'] = 42

        Internally this is implemented by going through a temporary test
        request context and since session handling could depend on
        request variables this function accepts the same arguments as
        :meth:`~flask.Flask.test_request_context` which are directly
        passed through.
        """
        if self.cookie_jar is None:
            raise RuntimeError('Session transactions only make sense '
                               'with cookies enabled.')
        app = self.application
        environ_overrides = kwargs.setdefault('environ_overrides', {})
        self.cookie_jar.inject_wsgi(environ_overrides)
        outer_reqctx = _request_ctx_stack.top
        with app.test_request_context(*args, **kwargs) as c:
            session_interface = app.session_interface
            sess = session_interface.open_session(app, c.request)
            if sess is None:
                raise RuntimeError('Session backend did not open a session. '
                                   'Check the configuration')

            # Since we have to open a new request context for the session
            # handling we want to make sure that we hide out own context
            # from the caller.  By pushing the original request context
            # (or None) on top of this and popping it we get exactly that
            # behavior.  It's important to not use the push and pop
            # methods of the actual request context object since that would
            # mean that cleanup handlers are called
            _request_ctx_stack.push(outer_reqctx)
            try:
                yield sess
            finally:
                _request_ctx_stack.pop()

            resp = app.response_class()
            if not session_interface.is_null_session(sess):
                session_interface.save_session(app, sess, resp)
            headers = resp.get_wsgi_headers(c.request.environ)
            self.cookie_jar.extract_wsgi(c.request.environ, headers)
Beispiel #8
0
def main():
    if len(sys.argv) < 2:
        complain_usage()

    global_conf.logging()
    # make Flask-SQLalchemy happy
    _request_ctx_stack.push(1)
    db.create_all()
    if sys.argv[1] == "sync":
        return
    if sys.argv[1] == "glance":
        migrate_glance()
    elif sys.argv[1] == "nova":
        migrate_nova()
    elif sys.argv[1] == "billing_v1" and len(sys.argv) >= 3:
        migrate_billing_v1(sys.argv[2])
    else:
        complain_usage()