當前位置: 首頁>>代碼示例>>Python>>正文


Python Config.update方法代碼示例

本文整理匯總了Python中flask.Config.update方法的典型用法代碼示例。如果您正苦於以下問題:Python Config.update方法的具體用法?Python Config.update怎麽用?Python Config.update使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在flask.Config的用法示例。


在下文中一共展示了Config.update方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: setup_config

# 需要導入模塊: from flask import Config [as 別名]
# 或者: from flask.Config import update [as 別名]
def setup_config(config):
    app_abspath = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
    app_config = Config(app_abspath)
    app_config.from_object('superdesk.default_settings')

    update_config(app_config)
    app_config.update(config or {}, **{
        'APP_ABSPATH': app_abspath,
        'DEBUG': True,
        'TESTING': True,
    })

    logging.getLogger('superdesk').setLevel(logging.WARNING)
    logging.getLogger('elastic').setLevel(logging.WARNING)  # elastic datalayer
    logging.getLogger('elasticsearch').setLevel(logging.WARNING)
    logging.getLogger('urllib3').setLevel(logging.WARNING)
    return app_config
開發者ID:superdesk,項目名稱:superdesk-core,代碼行數:19,代碼來源:__init__.py

示例2: ConfigurationRegistry

# 需要導入模塊: from flask import Config [as 別名]
# 或者: from flask.Config import update [as 別名]
class ConfigurationRegistry(ModuleDiscoveryRegistry):
    """
    Specialized ``ModuleDiscoveryRegistry`` that search for ``config`` modules
    in a list of Python packages and merge them into the Flask application
    config without overwriting already set variables.

    :param app: A Flask application
    :param registry_namespace: The registry namespace of an
        ``ImportPathRegistry`` with a list Python packages to search for
        ``config`` modules in. Defaults to ``packages``.
    """
    def __init__(self, app, registry_namespace=None):
        super(ConfigurationRegistry, self).__init__(
            'config',
            registry_namespace=registry_namespace,
            with_setup=False,
        )

        # Create a new configuration module to collect configuration in.
        from flask import Config
        self.new_config = Config(app.config.root_path)

        # Auto-discover configuration in packages
        self.discover(app)

        # Overwrite default configuration with user specified configuration
        self.new_config.update(app.config)
        app.config = self.new_config

    def register(self, new_object):
        """
        Register a new ``config`` module.

        :param new_object: The configuration module.
            ``app.config.from_object()`` will be called on it.
        """
        self.new_config.from_object(new_object)
        super(ConfigurationRegistry, self).register(new_object)

    def unregister(self, *args, **kwargs):
        """
        It is not possible to unregister configuration.
        """
        raise NotImplementedError()
開發者ID:GiorgosPa,項目名稱:flask-registry,代碼行數:46,代碼來源:appdiscovery.py

示例3: setup

# 需要導入模塊: from flask import Config [as 別名]
# 或者: from flask.Config import update [as 別名]
def setup(context=None, config=None, app_factory=get_app):

    app_abspath = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
    app_config = Config(app_abspath)
    app_config.from_object('superdesk.tests.test_settings')
    app_config['APP_ABSPATH'] = app_abspath

    app_config.update(get_test_settings())
    app_config.update(config or {})

    app_config.update({
        'DEBUG': True,
        'TESTING': True,
    })

    app = app_factory(app_config)
    logger = logging.getLogger('superdesk')
    logger.setLevel(logging.ERROR)
    logger = logging.getLogger('elasticsearch')
    logger.setLevel(logging.ERROR)
    logger = logging.getLogger('urllib3')
    logger.setLevel(logging.ERROR)
    drop_elastic(app)
    drop_mongo(app)

    # create index again after dropping it
    app.data.init_elastic(app)

    if context:
        context.app = app
        context.client = app.test_client()
開發者ID:MiczFlor,項目名稱:superdesk-core,代碼行數:33,代碼來源:__init__.py

示例4: ConfigurationRegistry

# 需要導入模塊: from flask import Config [as 別名]
# 或者: from flask.Config import update [as 別名]
class ConfigurationRegistry(ModuleDiscoveryRegistry):
    """
    Specialized import path registry that takes the initial list of import
    paths from ``PACKAGES`` configuration variable.

    Example::

        app.extensions['registry']['packages'] = PackageRegistry()
        app.extendsions['registry']['config'] = ConfigurationRegistry(
            _app, base_config='invenio.core.config'
        )
    """
    def __init__(self, app, registry_namespace=None):
        super(ConfigurationRegistry, self).__init__(
            'config',
            registry_namespace=registry_namespace,
            with_setup=False,
        )

        # Create a new configuration module to collect configuration in.
        from flask import Config
        self.new_config = Config(app.config.root_path)

        # Auto-discover configuration in packages
        self.discover(app)

        # Overwrite default configuration with user specified configuration
        self.new_config.update(app.config)
        app.config = self.new_config

    def register(self, new_object):
        self.new_config.from_object(new_object)
        super(ConfigurationRegistry, self).register(new_object)

    def unregister(self, *args, **kwargs):
        raise NotImplementedError()
開發者ID:jirikuncar,項目名稱:flask-registry,代碼行數:38,代碼來源:appdiscovery.py

示例5: create_app

# 需要導入模塊: from flask import Config [as 別名]
# 或者: from flask.Config import update [as 別名]
def create_app(config_file=None, **kwargs):
    """
    Create a new eve app object and initialize everything.

    User configuration can be loaded in the following order:

    1. Use the `config_file` arg to specify a file
    2. If `config_file` is `None`, you set the environment variable
       `AMIVAPI_CONFIG` to the path of your config file
    3. If no environment variable is set either, `config.py` in the current
       working directory is used

    Args:
        config (path): Specify config file to use.
        kwargs: All other key-value arguments will be used to update the config
    Returns:
        (Eve): The Eve application
    """
    # Load config
    config = Config(getcwd())
    config.from_object("amivapi.settings")

    # Specified path > environment var > default path; abspath for better log
    user_config = abspath(config_file or getenv('AMIVAPI_CONFIG', 'config.py'))
    try:
        config.from_pyfile(user_config)
        config_status = "Config loaded: %s" % user_config
    except IOError:
        config_status = "No config found."

    config.update(kwargs)

    # Initialize empty domain to create Eve object, register resources later
    config['DOMAIN'] = {}

    app = Eve("amivapi",  # Flask needs this name to find the static folder
              settings=config,
              validator=ValidatorAMIV)
    app.logger.info(config_status)

    # Set up error logging with sentry
    init_sentry(app)

    # Create LDAP connector
    ldap.init_app(app)

    # Initialize modules to register resources, validation, hooks, auth, etc.
    users.init_app(app)
    auth.init_app(app)
    events.init_app(app)
    groups.init_app(app)
    blacklist.init_app(app)
    joboffers.init_app(app)
    beverages.init_app(app)
    studydocs.init_app(app)
    cascade.init_app(app)
    cron.init_app(app)
    documentation.init_app(app)

    # Fix that eve doesn't run hooks on embedded documents
    app.on_fetched_item += utils.run_embedded_hooks_fetched_item
    app.on_fetched_resource += utils.run_embedded_hooks_fetched_resource

    return app
開發者ID:amiv-eth,項目名稱:amivapi,代碼行數:66,代碼來源:bootstrap.py


注:本文中的flask.Config.update方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。