X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=manga%2Flib.py;h=7988438e2610785fac2473114d2c552c091545da;hb=07be272b3a303f89e8d58492f9b140cd1ce300b2;hp=712de718ce1025d1f50c78c726780b0cd9a8fe85;hpb=943a9376573acfc7fca6a4cc723463a18b119253;p=automanga.git diff --git a/manga/lib.py b/manga/lib.py index 712de71..7988438 100644 --- a/manga/lib.py +++ b/manga/lib.py @@ -9,3 +9,31 @@ class manga(pagelist): class page(object): pass + +class pageiter(object): + def __init__(self, root): + self.nstack = [0] + self.lstack = [root] + + def next(self): + while True: + if len(self.nstack) == 0: + raise StopIteration + try: + node = self.lstack[-1][self.nstack[-1]] + except IndexError: + self.lstack.pop() + self.nstack.pop() + if len(self.nstack) > 0: + self.nstack[-1] += 1 + continue + if isinstance(node, page): + nl = tuple(self.nstack) + self.nstack[-1] += 1 + return nl, node + elif isinstance(node, pagelist): + self.lstack.append(node) + self.nstack.append(0) + + def __iter__(self): + return self