本文整理汇总了Python中bottle.ConfigDict类的典型用法代码示例。如果您正苦于以下问题:Python ConfigDict类的具体用法?Python ConfigDict怎么用?Python ConfigDict使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ConfigDict类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: config_page
def config_page():
"""
Display general configuration.
Display specific static weblog engine configuration.
Allow to change values.
"""
check_config()
message = ''
message_type = 'none'
config = hymby.params
engine_config = hymby.engine.get_config(hymby)
if request.POST.get('save', '').strip():
r = request.POST
config_filename = hymby.params['filename']
# Write changes using an ugly method: Get current config, and update it with form values. Then write all in the config.
conf = ConfigDict().load_config(config_filename)
for field in dict(r):
# do not take save button value
if field == 'save':
continue
value = r[field]
conf.update('general', {field: value})
reset_config(conf)
refresh()
message = 'General configuration updated.'
message_type = 'success'
config = hymby.params # needed as we update it
elif request.POST.get('save_engine'):
r = request.POST
hymby.engine.set_config(hymby, dict(r))
refresh()
message = '%s Configuration updated.' % hymby.params.get('general.engine', '')
message_type = 'success'
engine_config = hymby.engine.get_config(hymby) # needed as we update it
return template('config', title='Configuration', config=config, engine_config=engine_config, message=message, message_type=message_type)
示例2: test_gc_overlays
def test_gc_overlays(self):
root = ConfigDict()
overlay = root._make_overlay()
del overlay
import gc; gc.collect()
root._make_overlay() # This triggers the weakref-collect
self.assertEqual(len(root._overlays), 1)
示例3: test_issue588
def test_issue588(self):
"""`ConfigDict` namespaces break route options"""
c = ConfigDict()
c.load_dict({'a': {'b': 'c'}}, make_namespaces=True)
self.assertEqual('c', c['a.b'])
self.assertEqual('c', c['a']['b'])
self.assertEqual({'b': 'c'}, c['a'])
示例4: test_load_dict
def test_load_dict(self):
c = ConfigDict()
d = dict(a=dict(b=dict(foo=5, bar=6), baz=7))
c.load_dict(d)
self.assertEqual(c['a.b.foo'], 5)
self.assertEqual(c['a.b.bar'], 6)
self.assertEqual(c['a.baz'], 7)
示例5: test_attr_access
def test_attr_access(self):
""" ConfigDict allow attribute access to keys. """
c = ConfigDict()
c.test = 5
self.assertEqual(5, c.test)
self.assertEqual(5, c['test'])
c['test'] = 6
self.assertEqual(6, c.test)
self.assertEqual(6, c['test'])
del c.test
self.assertTrue('test' not in c)
示例6: test_load_config
def test_load_config(self):
c = ConfigDict()
c.load_config(self.config_file.name)
self.assertDictEqual({
'compression.default': '45',
'compression.status': 'single',
'default': '45',
'namespace.key': 'test',
'namespace.section.default': 'otherDefault',
'namespace.section.sub.namespace.key': 'test2',
'port': '8080'}, c)
示例7: test_fallback
def test_fallback(self):
fallback = ConfigDict()
fallback['key'] = 'fallback'
primary = ConfigDict()
primary._set_fallback(fallback)
# Check copy of existing values from fallback to primary
self.assertEqual(primary['key'], 'fallback')
# Check value change in fallback
fallback['key'] = 'fallback2'
self.assertEqual(fallback['key'], 'fallback2')
self.assertEqual(primary['key'], 'fallback2')
# Check value change in primary
primary['key'] = 'primary'
self.assertEqual(fallback['key'], 'fallback2')
self.assertEqual(primary['key'], 'primary')
# Check delete of mirrored value in primary
del primary['key']
self.assertEqual(fallback['key'], 'fallback2')
self.assertEqual(primary['key'], 'fallback2')
# Check delete on mirrored key in fallback
del fallback['key']
self.assertTrue('key' not in primary)
self.assertTrue('key' not in fallback)
# Check new key in fallback
fallback['key2'] = 'fallback'
self.assertEqual(fallback['key2'], 'fallback')
self.assertEqual(primary['key2'], 'fallback')
# Check new key in primary
primary['key3'] = 'primary'
self.assertEqual(primary['key3'], 'primary')
self.assertTrue('key3' not in fallback)
# Check delete of primary-only key
del primary['key3']
self.assertTrue('key3' not in primary)
self.assertTrue('key3' not in fallback)
# Check delete of fallback value
del fallback['key2']
self.assertTrue('key2' not in primary)
self.assertTrue('key2' not in fallback)
示例8: test_load_dict
def test_load_dict(self):
c = ConfigDict()
d = dict(a=dict(b=dict(foo=5, bar=6), baz=7))
c.load_dict(d)
self.assertEqual(c['a.b.foo'], 5)
self.assertEqual(c['a.b.bar'], 6)
self.assertEqual(c['a.baz'], 7)
# unicode keys (see issue #720)
try:
key = unichr(12354)
except NameError:
key = chr(12354)
c = ConfigDict()
c.load_dict({key: 'value'})
self.assertEqual('value', c[key])
c = ConfigDict()
c.load_dict({key: {'subkey': 'value'}})
self.assertEqual('value', c[key + '.subkey'])
示例9: test_load_module
def test_load_module(self):
c = ConfigDict()
c.load_module('example_settings', True)
self.assertEqual(c['A.B.C'], 3)
c = ConfigDict()
c.load_module('example_settings', False)
self.assertEqual(c['A']['B']['C'], 3)
示例10: test_meta
def test_meta(self):
c = ConfigDict()
c.meta_set('bool', 'filter', bool)
c.meta_set('int', 'filter', int)
c['bool'] = 'I am so true!'
c['int'] = '6'
self.assertTrue(c['bool'] is True)
self.assertEqual(c['int'], 6)
self.assertRaises(ValueError, lambda: c.update(int='not an int'))
示例11: test_issue720
def test_issue720(self):
"""Accept unicode keys."""
try:
key = unichr(12354)
except NameError:
key = chr(12354)
c = ConfigDict()
c.load_dict({key: 'value'})
self.assertEqual('value', c[key])
c = ConfigDict()
c.load_dict({key: {'subkey': 'value'}})
self.assertEqual('value', c[key + '.subkey'])
示例12: ConfigDict
from bottle import ConfigDict
app_config = ConfigDict()
app_config.load_dict({
'app': {
'debug': True,
'timezone': 'Europe/Moscow',
'server': 'tornado',
'port': 5040,
'auth': {
'admin': '$2a$10$YOUR-BCRYPT-HASH'
},
'db': {
'path': './data/sqlite.db'
}
},
'blog': {
'label': {'read_more': 'Read full article'},
'html_parser': 'lxml', # you must install 'lxml' package or use 'html.parser' instead
},
'feed': {
'author': 'Nikita Dementev',
'title': 'Neutral notes',
'subtitle': 'О коде и погоде',
},
'deploy': {
'production': {
'host': '[email protected]',
'key_file': '~/.ssh/same_rsa',
'target_dir': '~/www/example.com'
}
示例13: test_namespaces
def test_namespaces(self):
c = ConfigDict()
c.update('a.b', key='value')
self.assertEqual(c['a.b.key'], 'value')
示例14: test_update
def test_update(self):
c = ConfigDict()
c['key'] = 'value'
c.update(key='value2', key2='value3')
self.assertEqual(c['key'], 'value2')
self.assertEqual(c['key2'], 'value3')
示例15: test_string_save_keys
def test_string_save_keys(self):
c = ConfigDict()
with self.assertRaises(TypeError):
c[5] = 'value'
with self.assertRaises(TypeError):
c.load_dict({5: 'value'})