PERMANENT_SESSION_LIFETIME can now be an integer. This fixes #310
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Armin Ronacher · committed by Armin Ronacher · parent 6d0b326 · Browse files · 3 files·+35 added−9 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+35 added−9 removed
- other:+35 added−9 removed
Provenance
- Commit
6dccf77- Tree
18da9c1- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
6d0b326
3 files changed+35 added−9 removed
modified:docs/api.rst+7 added
215 unmodified lines216 217 .. autoclass:: SessionMixin218 :members:219 220+.. admonition:: Notice221 222+ The ``PERMANENT_SESSION_LIFETIME`` config key can also be an integer223+ starting with Flask 0.8. Either catch this down yourself or use224+ the :attr:`~flask.Flask.permanent_session_lifetime` attribute on the225+ app which converts the result to an integer automatically.226+227+228 Test Client229 -----------230 231 .. currentmodule:: flask.testing393 unmodified linesmodified:docs/config.rst+2 added
84 unmodified lines85 with the secure flag. Defaults to86 `False`.87 ``PERMANENT_SESSION_LIFETIME`` the lifetime of a permanent session as88 :class:`datetime.timedelta` object.89+ Starting with Flask 0.8 this can also be90+ an integer representing seconds.91 ``USE_X_SENDFILE`` enable/disable x-sendfile92 ``LOGGER_NAME`` the name of the logger93 ``SERVER_NAME`` the name and port number of the server.94 Required for subdomain support (e.g.:289 unmodified linesmodified:flask/app.py+26 added-9 removed
175 unmodified lines176 #: This attribute can also be configured from the config with the177 #: `SESSION_COOKIE_NAME` configuration key. Defaults to ``'session'``178 session_cookie_name = ConfigAttribute('SESSION_COOKIE_NAME')179 180- #: A :class:`~datetime.timedelta` which is used to set the expiration181- #: date of a permanent session. The default is 31 days which makes a182- #: permanent session survive for roughly one month.183- #:184- #: This attribute can also be configured from the config with the185- #: `PERMANENT_SESSION_LIFETIME` configuration key. Defaults to186- #: ``timedelta(days=31)``187- permanent_session_lifetime = ConfigAttribute('PERMANENT_SESSION_LIFETIME')188-180 #: Enable this if you want to use the X-Sendfile feature. Keep in181 #: mind that the server has to support this. This only affects files182 #: sent with the :func:`send_file` method.183 #:301 unmodified lines485 if rv is not None:486 return rv487 return self.debug488 489+ def _get_permanent_session_lifetime(self):490+ """A :class:`~datetime.timedelta` which is used to set the expiration491+ date of a permanent session. The default is 31 days which makes a492+ permanent session survive for roughly one month.493+494+ This attribute can also be configured from the config with the495+ `PERMANENT_SESSION_LIFETIME` configuration key. Defaults to496+ ``timedelta(days=31)``.497+498+ If you want to have this value as seconds you can use ``total_seconds()``::499+500+ app.permanent_session_lifetime.total_seconds()501+502+ Note that the config key can be a timedelta object or number of seconds503+ as integer since Flask 0.8.504+ """505+ rv = self.config['PERMANENT_SESSION_LIFETIME']506+ if not isinstance(rv, timedelta):507+ return timedelta(seconds=rv)508+ return rv509+ def _set_permanent_session_lifetime(self, value):510+ self.config['PERMANENT_SESSION_LIFETIME'] = value511+ permanent_session_lifetime = property(_get_permanent_session_lifetime,512+ _set_permanent_session_lifetime)513+ del _get_permanent_session_lifetime, _set_permanent_session_lifetime514+515 @property516 def logger(self):517 """A :class:`logging.Logger` object for this application. The518 default configuration is to log to stderr if the application is1010 unmodified lines