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): def __init__(self, toc, is_periodical):
self.strings = OrderedDict() self.strings = OrderedDict()
for item in toc.iterdescendants(): for item in toc.iterdescendants(breadth_first=True):
self.strings[item.title] = 0 self.strings[item.title] = 0
if is_periodical: if is_periodical:
self.strings[item.klass] = 0 self.strings[item.klass] = 0

View File

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