当前位置: 首页>>代码示例>>Python>>正文


Python ConfigManager.with_namespace方法代码示例

本文整理汇总了Python中everett.manager.ConfigManager.with_namespace方法的典型用法代码示例。如果您正苦于以下问题:Python ConfigManager.with_namespace方法的具体用法?Python ConfigManager.with_namespace怎么用?Python ConfigManager.with_namespace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在everett.manager.ConfigManager的用法示例。


在下文中一共展示了ConfigManager.with_namespace方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from everett.manager import ConfigManager [as 别名]
# 或者: from everett.manager.ConfigManager import with_namespace [as 别名]
def main(args):
    # Build configuration object just like we do in Antenna.
    config = ConfigManager([
        # Pull configuration from env file specified as ANTENNA_ENV
        ConfigEnvFileEnv([os.environ.get('ANTENNA_ENV')]),

        # Pull configuration from environment variables
        ConfigOSEnv()
    ])

    # We create it in the crashstorage namespace because that's how Antenna
    # uses it. This makes it easier to use existing configuration.
    conn = S3Connection(config.with_namespace('crashstorage'), no_verify=True)

    # First, check to see if the bucket is already created.
    try:
        print('Checking to see if bucket "%s" exists...' % conn.bucket)
        conn.verify_configuration()
        print('Bucket exists.')

    except ClientError as exc:
        print(str(exc))
        if 'HeadBucket operation: Not Found' in str(exc):
            print('Bucket not found. Creating %s ...' % conn.bucket)
            # Create the bucket.
            conn._create_bucket()
            print('Bucket created.')
        else:
            raise
开发者ID:willkg,项目名称:antenna,代码行数:31,代码来源:create_s3_bucket.py

示例2: test_with_namespace

# 需要导入模块: from everett.manager import ConfigManager [as 别名]
# 或者: from everett.manager.ConfigManager import with_namespace [as 别名]
def test_with_namespace():
    config = ConfigManager([
        ConfigDictEnv({
            'FOO_BAR': 'foobaz',
            'BAR': 'baz',
            'BAT': 'bat',
        })
    ])

    # Verify the values first
    assert config('bar', namespace=['foo']) == 'foobaz'
    assert config('bar') == 'baz'
    assert config('bat') == 'bat'

    # Create the namespaced config
    config_with_namespace = config.with_namespace('foo')
    assert config_with_namespace('bar') == 'foobaz'

    # Verify 'bat' is not available because it's not in the namespace
    with pytest.raises(ConfigurationError):
        config_with_namespace('bat')
开发者ID:pmac,项目名称:everett,代码行数:23,代码来源:test_manager.py

示例3: test_with_options

# 需要导入模块: from everett.manager import ConfigManager [as 别名]
# 或者: from everett.manager.ConfigManager import with_namespace [as 别名]
def test_with_options():
    """Verify .with_options() restricts configuration"""
    config = ConfigManager([
        ConfigDictEnv({
            'FOO_BAR': 'a',
            'FOO_BAZ': 'b',

            'BAR': 'c',
            'BAZ': 'd',
        })
    ])

    class SomeComponent(RequiredConfigMixin):
        required_config = ConfigOptions()
        required_config.add_option(
            'baz',
            default='',
            doc='some help here',
            parser=str
        )

        def __init__(self, config):
            self.config = config.with_options(self)

    # Create the component with regular config
    comp = SomeComponent(config)
    assert comp.config('baz') == 'd'
    with pytest.raises(ConfigurationError):
        # This is not a valid option for this component
        comp.config('bar')

    # Create the component with config in the "foo" namespace
    comp2 = SomeComponent(config.with_namespace('foo'))
    assert comp2.config('baz') == 'b'
    with pytest.raises(ConfigurationError):
        # This is not a valid option for this component
        comp2.config('bar')
开发者ID:willkg,项目名称:everett,代码行数:39,代码来源:test_component.py


注:本文中的everett.manager.ConfigManager.with_namespace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。