string)
return string
+ def _parents(me):
+ """Yield this section's parents."""
+ try: names = me._itemmap['@inherit']
+ except KeyError: return
+ for name in names.replace(',', ' ').split():
+ yield me._cp.section(name)
+
def _get(me, key, map = None, path = None):
"""
Low-level option-fetching method.
except KeyError: pass
else: return v, path[:]
- ## No, apparently, not. Find out our list of parents.
- try:
- parents = [me._cp.section(p) for p in
- me._itemmap['@inherit'].replace(',', ' ').split()]
- except KeyError:
- parents = []
-
## Initially we have no idea.
value = None
winner = None
## Go through our parents and ask them what they think.
map[me.name] = True, None
- for p in parents:
+ for p in me._parents():
## See whether we get an answer. If not, keep on going.
v, pp = p._get(key, map, path)
## Initialize for a depth-first walk of the inheritance graph.
d = {}
visited = {}
- stack = [me.name]
+ stack = [me]
## Visit nodes, collecting their keys. Don't believe the values:
## resolving inheritance is too hard to do like this.
while stack:
- sec = me._cp.section(stack.pop())
+ sec = stack.pop()
if sec.name in visited: continue
visited[sec.name] = True
+ stack += sec._parents()
- for key, value in sec._itemmap.iteritems():
- if key == '@inherit': stack += value.replace(',', ' ').split()
- else: d[key] = None
+ for key in sec._itemmap.iterkeys():
+ if key != '@inherit': d[key] = None
## And we're done.
return d.iterkeys()