This commit is contained in:
Kovid Goyal 2011-07-26 18:29:12 -06:00
parent 3cd3ca6acd
commit 0ab0246048
2 changed files with 12 additions and 5 deletions

View File

@ -31,7 +31,7 @@ class CNCX(object): # {{{
def __init__(self, toc, is_periodical):
self.strings = OrderedDict()
for item in toc.iterdescendants():
for item in toc.iterdescendants(breadth_first=True):
self.strings[item.title] = 0
if is_periodical:
self.strings[item.klass] = 0

View File

@ -1680,11 +1680,18 @@ class TOC(object):
return True
return False
def iterdescendants(self):
def iterdescendants(self, breadth_first=False):
"""Iterate over all descendant nodes in depth-first order."""
for child in self.nodes:
for node in child.iter():
yield node
if breadth_first:
for child in self.nodes:
yield child
for child in self.nodes:
for node in child.iterdescendants(breadth_first=True):
yield node
else:
for child in self.nodes:
for node in child.iter():
yield node
def __iter__(self):
"""Iterate over all immediate child nodes."""