|
41 | 41 | _logger_lock = Lock()
|
42 | 42 |
|
43 | 43 |
|
| 44 | +def _make_timedelta(value): |
| 45 | + if not isinstance(value, timedelta): |
| 46 | + return timedelta(seconds=value) |
| 47 | + return value |
| 48 | + |
| 49 | + |
44 | 50 | def setupmethod(f):
|
45 | 51 | """Wraps a method so that it performs a check in debug mode if the
|
46 | 52 | first request was already handled.
|
@@ -177,6 +183,16 @@ class Flask(_PackageBoundObject):
|
177 | 183 | #: `SESSION_COOKIE_NAME` configuration key. Defaults to ``'session'``
|
178 | 184 | session_cookie_name = ConfigAttribute('SESSION_COOKIE_NAME')
|
179 | 185 |
|
| 186 | + #: A :class:`~datetime.timedelta` which is used to set the expiration |
| 187 | + #: date of a permanent session. The default is 31 days which makes a |
| 188 | + #: permanent session survive for roughly one month. |
| 189 | + #: |
| 190 | + #: This attribute can also be configured from the config with the |
| 191 | + #: `PERMANENT_SESSION_LIFETIME` configuration key. Defaults to |
| 192 | + #: ``timedelta(days=31)`` |
| 193 | + permanent_session_lifetime = ConfigAttribute('PERMANENT_SESSION_LIFETIME', |
| 194 | + get_converter=_make_timedelta) |
| 195 | + |
180 | 196 | #: Enable this if you want to use the X-Sendfile feature. Keep in
|
181 | 197 | #: mind that the server has to support this. This only affects files
|
182 | 198 | #: sent with the :func:`send_file` method.
|
@@ -486,32 +502,6 @@ def preserve_context_on_exception(self):
|
486 | 502 | return rv
|
487 | 503 | return self.debug
|
488 | 504 |
|
489 |
| - def _get_permanent_session_lifetime(self): |
490 |
| - """A :class:`~datetime.timedelta` which is used to set the expiration |
491 |
| - date of a permanent session. The default is 31 days which makes a |
492 |
| - permanent session survive for roughly one month. |
493 |
| -
|
494 |
| - This attribute can also be configured from the config with the |
495 |
| - `PERMANENT_SESSION_LIFETIME` configuration key. Defaults to |
496 |
| - ``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 seconds |
503 |
| - 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 rv |
509 |
| - def _set_permanent_session_lifetime(self, value): |
510 |
| - self.config['PERMANENT_SESSION_LIFETIME'] = value |
511 |
| - permanent_session_lifetime = property(_get_permanent_session_lifetime, |
512 |
| - _set_permanent_session_lifetime) |
513 |
| - del _get_permanent_session_lifetime, _set_permanent_session_lifetime |
514 |
| - |
515 | 505 | @property
|
516 | 506 | def logger(self):
|
517 | 507 | """A :class:`logging.Logger` object for this application. The
|
|
0 commit comments