本文整理匯總了Python中kamaki.cli.config.Config.safe_to_print方法的典型用法代碼示例。如果您正苦於以下問題:Python Config.safe_to_print方法的具體用法?Python Config.safe_to_print怎麽用?Python Config.safe_to_print使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類kamaki.cli.config.Config
的用法示例。
在下文中一共展示了Config.safe_to_print方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: safe_to_print
# 需要導入模塊: from kamaki.cli.config import Config [as 別名]
# 或者: from kamaki.cli.config.Config import safe_to_print [as 別名]
def safe_to_print(self):
"""Enhance Config.safe_to_print to handle syncs"""
dump = Config.safe_to_print(self)
for r, d in self.items(SYNC_PREFIX, include_defaults=False):
dump += u'\n[%s "%s"]\n' % (SYNC_PREFIX, escape_ctrl_chars(r))
for k, v in d.items():
dump += u'%s = %s\n' % (
escape_ctrl_chars(k), escape_ctrl_chars(v))
return dump
示例2: test_safe_to_print
# 需要導入模塊: from kamaki.cli.config import Config [as 別名]
# 或者: from kamaki.cli.config.Config import safe_to_print [as 別名]
def test_safe_to_print(self):
itemsd = {
'global': {
'opt1': 'v1',
'opt2': 2,
'opt3': u'\u03c4\u03b9\u03bc\u03ae',
'opt4': 'un\b\bdeleted'
}, 'cloud': {
'cld1': {'url': 'url1', 'token': 'token1'},
'cld2': {'url': u'\u03bf\u03c5\u03b1\u03c1\u03ad\u03bb'}
}
}
from kamaki.cli.config import Config
_cnf = Config(path=self.f.name)
bu_func = Config.items
try:
Config.items = (
lambda cls, opt, include_defaults: itemsd[opt].items())
saved = _cnf.safe_to_print().split('\n')
glb, cld = saved[:5], saved[6:]
self.assertEqual(u'[global]', glb[0])
self.assertTrue(u'opt1 = v1' in glb)
self.assertTrue(u'opt2 = 2' in glb)
self.assertTrue(u'opt3 = \u03c4\u03b9\u03bc\u03ae' in glb)
self.assertTrue(u'opt4 = un\\x08\\x08deleted' in glb)
self.assertTrue('[cloud "cld1"]' in cld)
cld1_i = cld.index('[cloud "cld1"]')
cld1 = cld[cld1_i: cld1_i + 3]
self.assertTrue('url = url1' in cld1)
self.assertTrue('token = token1' in cld1)
self.assertTrue('[cloud "cld2"]' in cld)
cld2_i = cld.index('[cloud "cld2"]')
self.assertEqual(
u'url = \u03bf\u03c5\u03b1\u03c1\u03ad\u03bb', cld[cld2_i + 1])
finally:
Config.items = bu_func