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 b26aeba · 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
604 unmodified lines
605 def _record(self, func):606 self._register_events.append(func)607608609class ConfigAttribute(object):610 """Makes an attribute forward to the config"""611612 def __init__(self, name):613 self.__name__ = name614615 def __get__(self, obj, type=None):616 if obj is None:617 return self618 return obj.config[self.__name__]619620 def __set__(self, obj, value):621 obj.config[self.__name__] = value622623624class Flask(_PackageBoundObject):625 """The flask object implements a WSGI application and acts as the central626 object. It is passed the name of the module or package of the627 application. Once it is created it will act as a central registry for
25 unmodified lines
653 #: you can set this value to `None` in which case no URL rule is added654 #: and the development server will no longer serve any static files.655 static_path = '/static'656657 #: the debug flag. Set this to `True` to enable debugging of the658 #: application. In debug mode the debugger will kick in when an unhandled659 #: exception ocurrs and the integrated server will automatically reload660 #: the application if changes in the code are detected.661 debug = ConfigAttribute('debug')662663 #: if a secret key is set, cryptographic components can use this to664 #: sign cookies and other things. Set this to a complex random value665 #: when you want to use the secure cookie for instance.645 secret_key = None666 secret_key = ConfigAttribute('secret_key')667668 #: The secure cookie uses this for the name of the session cookie648 session_cookie_name = 'session'669 session_cookie_name = ConfigAttribute('session.cookie_name')670671 #: A :class:`~datetime.timedelta` which is used to set the expiration672 #: date of a permanent session. The default is 31 days which makes a673 #: permanent session survive for roughly one month.653 permanent_session_lifetime = timedelta(days=31)674 permanent_session_lifetime = ConfigAttribute('session.permanent_lifetime')675676 #: Enable this if you want to use the X-Sendfile feature. Keep in677 #: mind that the server has to support this. This only affects files678 #: sent with the :func:`send_file` method.679 #:680 #: .. versionadded:: 0.2660 use_x_sendfile = False681 use_x_sendfile = ConfigAttribute('use_x_sendfile')682683 #: the logging format used for the debug logger. This is only used when684 #: the application is in debug mode, otherwise the attached logging685 #: handler does the formatting.
11 unmodified lines
697 autoescape=True,698 extensions=['jinja2.ext.autoescape', 'jinja2.ext.with_']699 )700701 #: default configuration parameters702 default_config = ImmutableDict({703 'debug': False,704 'secret_key': None,705 'session.cookie_name': 'session',706 'session.permanent_lifetime': timedelta(days=31),707 'use_x_sendfile': False708 })709680 def __init__(self, import_name):710 def __init__(self, import_name, config=None):711 _PackageBoundObject.__init__(self, import_name)712683 #: the debug flag. Set this to `True` to enable debugging of684 #: the application. In debug mode the debugger will kick in685 #: when an unhandled exception ocurrs and the integrated server686 #: will automatically reload the application if changes in the687 #: code are detected.688 self.debug = False713 #: the configuration dictionary714 self.config = self.default_config.copy()715 if config:716 self.config.update(config)717718 #: a dictionary of all view functions registered. The keys will719 #: be function names which are also used to generate URLs and720 #: the values are the function objects themselves.
532 unmodified lines