config.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:fleaker 作者: croscon 项目源码 文件源码
def add_post_configure_callback(self, callback, run_once=False):
        """Add a new callback to be run after every call to :meth:`configure`.

        Functions run at the end of :meth:`configure` are given the
        application's resulting configuration and the arguments passed to
        :meth:`configure`, in that order. As a note, this first argument will
        be an immutable dictionary.

        The return value of all registered callbacks is entirely ignored.

        Callbacks are run in the order they are registered, but you should
        never depend on another callback.

        .. admonition:: The "Resulting" Configuration

            The first argument to the callback is always the "resulting"
            configuration from the call to :meth:`configure`. What this means
            is you will get the Application's FROZEN configuration after the
            call to :meth:`configure` finished. Moreover, this resulting
            configuration will be an
            :class:`~werkzeug.datastructures.ImmutableDict`.

            The purpose of a Post Configure callback is not to futher alter the
            configuration, but rather to do lazy initialization for anything
            that absolutely requires the configuration, so any attempt to alter
            the configuration of the app has been made intentionally difficult!

        Args:
            callback (function):
                The function you wish to run after :meth:`configure`. Will
                receive the application's current configuration as the first
                arugment, and the same arguments passed to :meth:`configure` as
                the second.

        Keyword Args:
            run_once (bool):
                Should this callback run every time configure is called? Or
                just once and be deregistered? Pass ``True`` to only run it
                once.

        Returns:
            fleaker.base.BaseApplication:
                Returns itself for a fluent interface.
        """
        if run_once:
            self._post_configure_callbacks['single'].append(callback)
        else:
            self._post_configure_callbacks['multiple'].append(callback)

        return self
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号