Skip to content
Myr

Merge pull request #2347 from davidism/session-interface

Before adoption: this commit came in with the history the project adopted, so no landing records it.

deprecate app session methods in favor of session_interface

authored by David Lord · committed by GitHub · parents abf54c8, b9c8c9b · Browse files · 3 files+37 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+37 added−6 removed

  • other:+37 added−6 removed

3 files+37 added−6 removed

modified:flask/app.py+29 added-1 removed
8 unmodified lines
9 :license: BSD, see LICENSE for more details.10"""11import os12import sys13import warnings14from datetime import timedelta15from functools import update_wrapper16from itertools import chain17from threading import Lock
907 unmodified lines
925 session data in a signed cookie. This requires that the926 :attr:`secret_key` is set. Instead of overriding this method927 we recommend replacing the :class:`session_interface`.928929 .. deprecated: 1.0930 Will be removed in 1.1. Use ``session_interface.open_session``931 instead.932933 :param request: an instance of :attr:`request_class`.934 """935936 warnings.warn(DeprecationWarning(937 '"open_session" is deprecated and will be removed in 1.1. Use'938 ' "session_interface.open_session" instead.'939 ))940 return self.session_interface.open_session(self, request)941942 def save_session(self, session, response):943 """Saves the session if it needs updates. For the default944 implementation, check :meth:`open_session`. Instead of overriding this945 method we recommend replacing the :class:`session_interface`.946947 .. deprecated: 1.0948 Will be removed in 1.1. Use ``session_interface.save_session``949 instead.950951 :param session: the session to be saved (a952 :class:`~werkzeug.contrib.securecookie.SecureCookie`953 object)954 :param response: an instance of :attr:`response_class`955 """956957 warnings.warn(DeprecationWarning(958 '"save_session" is deprecated and will be removed in 1.1. Use'959 ' "session_interface.save_session" instead.'960 ))961 return self.session_interface.save_session(self, session, response)962963 def make_null_session(self):964 """Creates a new instance of a missing session. Instead of overriding965 this method we recommend replacing the :class:`session_interface`.966967 .. deprecated: 1.0968 Will be removed in 1.1. Use ``session_interface.make_null_session``969 instead.970971 .. versionadded:: 0.7972 """973974 warnings.warn(DeprecationWarning(975 '"make_null_session" is deprecated and will be removed in 1.1. Use'976 ' "session_interface.make_null_session" instead.'977 ))978 return self.session_interface.make_null_session(self)979980 @setupmethod981 def register_blueprint(self, blueprint, **options):
977 unmodified lines
1959 funcs = chain(funcs, reversed(self.after_request_funcs[None]))1960 for handler in funcs:1961 response = handler(response)1962 if not self.session_interface.is_null_session(ctx.session):1935 self.save_session(ctx.session, response)1963 self.session_interface.save_session(self, ctx.session, response)1964 return response19651966 def do_teardown_request(self, exc=_sentinel):1967 """Called after the actual request dispatching and will
150 unmodified lines
modified:flask/ctx.py+4 added-2 removed
327 unmodified lines
328 # Open the session at the moment that the request context is329 # available. This allows a custom open_session method to use the330 # request context (e.g. code that access database information331 # stored on `g` instead of the appcontext).332 self.session = self.app.open_session(self.request)332 session_interface = self.app.session_interface333 self.session = session_interface.open_session(self.app, self.request)334335 if self.session is None:334 self.session = self.app.make_null_session()336 self.session = session_interface.make_null_session(self.app)337338 def pop(self, exc=_sentinel):339 """Pops the request context and unbinds it by doing that. This will340 also trigger the execution of functions registered by the
72 unmodified lines
modified:flask/testing.py+4 added-3 removed
103 unmodified lines
104 environ_overrides = kwargs.setdefault('environ_overrides', {})105 self.cookie_jar.inject_wsgi(environ_overrides)106 outer_reqctx = _request_ctx_stack.top107 with app.test_request_context(*args, **kwargs) as c:108 sess = app.open_session(c.request)108 session_interface = app.session_interface109 sess = session_interface.open_session(app, c.request)110 if sess is None:111 raise RuntimeError('Session backend did not open a session. '112 'Check the configuration')113
10 unmodified lines
124 finally:125 _request_ctx_stack.pop()126127 resp = app.response_class()127 if not app.session_interface.is_null_session(sess):128 app.save_session(sess, resp)128 if not session_interface.is_null_session(sess):129 session_interface.save_session(app, sess, resp)130 headers = resp.get_wsgi_headers(c.request.environ)131 self.cookie_jar.extract_wsgi(c.request.environ, headers)132133 def open(self, *args, **kwargs):
29 unmodified lines