本文整理汇总了Python中salt.utils.odict.OrderedDict.iteritems方法的典型用法代码示例。如果您正苦于以下问题:Python OrderedDict.iteritems方法的具体用法?Python OrderedDict.iteritems怎么用?Python OrderedDict.iteritems使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类salt.utils.odict.OrderedDict
的用法示例。
在下文中一共展示了OrderedDict.iteritems方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: gen_ini
# 需要导入模块: from salt.utils.odict import OrderedDict [as 别名]
# 或者: from salt.utils.odict.OrderedDict import iteritems [as 别名]
def gen_ini(self):
yield '\n[{0}]\n'.format(self.name)
sections_dict = OrderedDict()
for name, value in self.iteritems():
if com_regx.match(name):
yield '{0}\n'.format(value)
elif isinstance(value, _Section):
sections_dict.update({name: value})
else:
yield '{0} {1} {2}\n'.format(name, self.sep, value)
for name, value in sections_dict.iteritems():
for line in value.gen_ini():
yield line
示例2: StateRegistry
# 需要导入模块: from salt.utils.odict import OrderedDict [as 别名]
# 或者: from salt.utils.odict.OrderedDict import iteritems [as 别名]
class StateRegistry(object):
"""
The StateRegistry holds all of the states that have been created.
"""
def __init__(self):
self.empty()
def empty(self):
self.states = OrderedDict()
self.requisites = []
def salt_data(self):
states = OrderedDict([
(id_, state())
for id_, state in self.states.iteritems()
])
self.empty()
return states
def add(self, id_, state):
if id_ in self.states:
raise DuplicateState("A state with id '%s' already exists" % id_)
# if we have requisites in our stack then add them to the state
if len(self.requisites) > 0:
for req in self.requisites:
if req.requisite not in state.kwargs:
state.kwargs[req.requisite] = []
state.kwargs[req.requisite].append(req())
self.states[id_] = state
def push_requisite(self, requisite):
self.requisites.append(requisite)
def pop_requisite(self):
del self.requisites[-1]
示例3: _uncomment_if_commented
# 需要导入模块: from salt.utils.odict import OrderedDict [as 别名]
# 或者: from salt.utils.odict.OrderedDict import iteritems [as 别名]
def _uncomment_if_commented(self, opt_key):
# should be called only if opt_key is not already present
# will uncomment the key if commented and create a place holder
# for the key where the correct value can be update later
# used to preserve the ordering of comments and commented options
# and to make sure options without sectons go above any section
options_backup = OrderedDict()
comment_index = None
for key, value in self.iteritems():
if comment_index is not None:
options_backup.update({key: value})
continue
if '#comment' not in key:
continue
opt_match = opt_regx.match(value.lstrip('#'))
if opt_match and opt_match.group(2) == opt_key:
comment_index = key
for key in options_backup:
self.pop(key)
self.pop(comment_index, None)
super(_Section, self).update({opt_key: None})
for key, value in options_backup.iteritems():
super(_Section, self).update({key: value})
示例4: StateRegistry
# 需要导入模块: from salt.utils.odict import OrderedDict [as 别名]
# 或者: from salt.utils.odict.OrderedDict import iteritems [as 别名]
class StateRegistry(object):
'''
The StateRegistry holds all of the states that have been created.
'''
def __init__(self):
self.empty()
def empty(self):
self.states = OrderedDict()
self.requisites = []
self.includes = []
self.extends = OrderedDict()
def include(self, *args):
self.includes += args
def salt_data(self):
states = OrderedDict([
(id_, state())
for id_, state in self.states.iteritems()
])
if self.includes:
states['include'] = self.includes
if self.extends:
states['extend'] = OrderedDict([
(id_, state())
for id_, state in self.extends.iteritems()
])
self.empty()
return states
def add(self, id_, state, extend=False):
if extend:
attr = self.extends
else:
attr = self.states
if id_ in attr:
raise DuplicateState("A state with id '%s' already exists" % id_)
# if we have requisites in our stack then add them to the state
if len(self.requisites) > 0:
for req in self.requisites:
if req.requisite not in state.kwargs:
state.kwargs[req.requisite] = []
state.kwargs[req.requisite].append(req())
attr[id_] = state
def extend(self, id_, state):
self.add(id_, state, extend=True)
def make_extend(self, name):
return StateExtend(name)
def push_requisite(self, requisite):
self.requisites.append(requisite)
def pop_requisite(self):
del self.requisites[-1]