Skip to content
Myr

Started working on config support

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 e432d83 · Browse files · 1 file+39 added−11 removed
This commit

State

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

Diff stats

1 file+39 added−11 removed

  • other:+39 added−11 removed

1 file+39 added−11 removed

modified:flask.py+39 added-11 removed
613 unmodified lines
614 def _record(self, func):615 self._register_events.append(func)616617618class ConfigAttribute(object):619 """Makes an attribute forward to the config"""620621 def __init__(self, name):622 self.__name__ = name623624 def __get__(self, obj, type=None):625 if obj is None:626 return self627 return obj.config[self.__name__]628629 def __set__(self, obj, value):630 obj.config[self.__name__] = value631632633class Flask(_PackageBoundObject):634 """The flask object implements a WSGI application and acts as the central635 object. It is passed the name of the module or package of the636 application. Once it is created it will act as a central registry for
25 unmodified lines
662 #: you can set this value to `None` in which case no URL rule is added663 #: and the development server will no longer serve any static files.664 static_path = '/static'665666 #: the debug flag. Set this to `True` to enable debugging of the667 #: application. In debug mode the debugger will kick in when an unhandled668 #: exception ocurrs and the integrated server will automatically reload669 #: the application if changes in the code are detected.670 debug = ConfigAttribute('debug')671672 #: if a secret key is set, cryptographic components can use this to673 #: sign cookies and other things. Set this to a complex random value674 #: when you want to use the secure cookie for instance.654 secret_key = None675 secret_key = ConfigAttribute('secret_key')676677 #: The secure cookie uses this for the name of the session cookie657 session_cookie_name = 'session'678 session_cookie_name = ConfigAttribute('session.cookie_name')679680 #: A :class:`~datetime.timedelta` which is used to set the expiration681 #: date of a permanent session. The default is 31 days which makes a682 #: permanent session survive for roughly one month.662 permanent_session_lifetime = timedelta(days=31)683 permanent_session_lifetime = ConfigAttribute('session.permanent_lifetime')684685 #: Enable this if you want to use the X-Sendfile feature. Keep in686 #: mind that the server has to support this. This only affects files687 #: sent with the :func:`send_file` method.688 #:689 #: .. versionadded:: 0.2669 use_x_sendfile = False690 use_x_sendfile = ConfigAttribute('use_x_sendfile')691692 #: the logging format used for the debug logger. This is only used when693 #: the application is in debug mode, otherwise the attached logging694 #: handler does the formatting.
11 unmodified lines
706 autoescape=True,707 extensions=['jinja2.ext.autoescape', 'jinja2.ext.with_']708 )709710 #: default configuration parameters711 default_config = ImmutableDict({712 'debug': False,713 'secret_key': None,714 'session.cookie_name': 'session',715 'session.permanent_lifetime': timedelta(days=31),716 'use_x_sendfile': False717 })718689 def __init__(self, import_name):719 def __init__(self, import_name, config=None):720 _PackageBoundObject.__init__(self, import_name)721692 #: the debug flag. Set this to `True` to enable debugging of693 #: the application. In debug mode the debugger will kick in694 #: when an unhandled exception ocurrs and the integrated server695 #: will automatically reload the application if changes in the696 #: code are detected.697 self.debug = False722 #: the configuration dictionary723 self.config = self.default_config.copy()724 if config:725 self.config.update(config)726727 #: a dictionary of all view functions registered. The keys will728 #: be function names which are also used to generate URLs and729 #: the values are the function objects themselves.
565 unmodified lines