Skip to content
Myr

Moved the conversion thing into the ConfigAttribute.

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 6dccf77 · Browse files · 3 files+27 added−28 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+27 added−28 removed

  • other:+27 added−28 removed

3 files+27 added−28 removed

modified:flask/testsuite/config.py+5 added
76 unmodified lines
77 else:78 self.assert_(0, 'expected config')79 self.assert_(not app.config.from_pyfile('missing.cfg', silent=True))8081 def test_session_lifetime(self):82 app = flask.Flask(__name__)83 app.config['PERMANENT_SESSION_LIFETIME'] = 4284 self.assert_equal(app.permanent_session_lifetime.total_seconds(), 42)858687class InstanceTestCase(FlaskTestCase):8889 def test_explicit_instance_paths(self):90 here = os.path.abspath(os.path.dirname(__file__))
92 unmodified lines
modified:flask/app.py+16 added-26 removed
39 unmodified lines
40# a lock used for logger initialization41_logger_lock = Lock()424344def _make_timedelta(value):45 if not isinstance(value, timedelta):46 return timedelta(seconds=value)47 return value484950def setupmethod(f):51 """Wraps a method so that it performs a check in debug mode if the52 first request was already handled.53 """
128 unmodified lines
182 #: This attribute can also be configured from the config with the183 #: `SESSION_COOKIE_NAME` configuration key. Defaults to ``'session'``184 session_cookie_name = ConfigAttribute('SESSION_COOKIE_NAME')185186 #: A :class:`~datetime.timedelta` which is used to set the expiration187 #: date of a permanent session. The default is 31 days which makes a188 #: permanent session survive for roughly one month.189 #:190 #: This attribute can also be configured from the config with the191 #: `PERMANENT_SESSION_LIFETIME` configuration key. Defaults to192 #: ``timedelta(days=31)``193 permanent_session_lifetime = ConfigAttribute('PERMANENT_SESSION_LIFETIME',194 get_converter=_make_timedelta)195196 #: Enable this if you want to use the X-Sendfile feature. Keep in197 #: mind that the server has to support this. This only affects files198 #: sent with the :func:`send_file` method.199 #:
301 unmodified lines
501 if rv is not None:502 return rv503 return self.debug504489 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.493494 This attribute can also be configured from the config with the495 `PERMANENT_SESSION_LIFETIME` configuration key. Defaults to496 ``timedelta(days=31)``.497498 If you want to have this value as seconds you can use ``total_seconds()``::499500 app.permanent_session_lifetime.total_seconds()501502 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_lifetime514505 @property506 def logger(self):507 """A :class:`logging.Logger` object for this application. The508 default configuration is to log to stderr if the application is
1010 unmodified lines
modified:flask/config.py+6 added-2 removed
19 unmodified lines
2021class ConfigAttribute(object):22 """Makes an attribute forward to the config"""2324 def __init__(self, name):24 def __init__(self, name, get_converter=None):25 self.__name__ = name26 self.get_converter = get_converter2728 def __get__(self, obj, type=None):29 if obj is None:30 return self30 return obj.config[self.__name__]31 rv = obj.config[self.__name__]32 if self.get_converter is not None:33 rv = self.get_converter(rv)34 return rv3536 def __set__(self, obj, value):37 obj.config[self.__name__] = value38
131 unmodified lines