本文整理汇总了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
示例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')
示例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')