deprecate app session methods in favor of session_interface
Before adoption: this commit came in with the history the project adopted, so no landing records it.
ref #1182
authored by David Lord · committed by David Lord · parent abf54c8 · 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
Provenance
- Commit
b9c8c9b- Tree
973f50d- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
abf54c8
3 files changed+37 added−6 removed
modified:flask/app.py+29 added-1 removed
8 unmodified lines9 :license: BSD, see LICENSE for more details.10 """11 import os12 import sys13+import warnings14 from datetime import timedelta15 from functools import update_wrapper16 from itertools import chain17 from threading import Lock907 unmodified lines925 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`.928 929+ .. deprecated: 1.0930+ Will be removed in 1.1. Use ``session_interface.open_session``931+ instead.932+933 :param request: an instance of :attr:`request_class`.934 """935+936+ 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)941 942 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`.946 947+ .. deprecated: 1.0948+ Will be removed in 1.1. Use ``session_interface.save_session``949+ instead.950+951 :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 """956+957+ 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)962 963 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`.966 967+ .. deprecated: 1.0968+ Will be removed in 1.1. Use ``session_interface.make_null_session``969+ instead.970+971 .. versionadded:: 0.7972 """973+974+ 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)979 980 @setupmethod981 def register_blueprint(self, blueprint, **options):977 unmodified lines1959 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 response1965 1966 def do_teardown_request(self, exc=_sentinel):1967 """Called after the actual request dispatching and will150 unmodified linesmodified:flask/ctx.py+4 added-2 removed
327 unmodified lines328 # 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)334+335 if self.session is None:334- self.session = self.app.make_null_session()336+ self.session = session_interface.make_null_session(self.app)337 338 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 the72 unmodified linesmodified:flask/testing.py+4 added-3 removed
103 unmodified lines104 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 lines124 finally:125 _request_ctx_stack.pop()126 127 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)132 133 def open(self, *args, **kwargs):29 unmodified lines