From 2292ad392d0a22f805c8e2e80ce5f4a06b1c7218 Mon Sep 17 00:00:00 2001 From: vicky Date: Mon, 30 May 2022 21:22:24 +0200 Subject: [PATCH] cleaned the pile output --- src/bootstraparse/modules/context_mngr.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/bootstraparse/modules/context_mngr.py b/src/bootstraparse/modules/context_mngr.py index 4602f4e..ac36bb3 100644 --- a/src/bootstraparse/modules/context_mngr.py +++ b/src/bootstraparse/modules/context_mngr.py @@ -277,11 +277,6 @@ class ContextManager: "table:row": ["table:separator", "table:row"] # TODO: Implement tables } - def __iter__(self): - for e in self.pile: - if e: - yield e - def encapsulate(self, start, end): """ Method to encapsulate a number of tokens together as a final container object @@ -380,7 +375,18 @@ class ContextManager: error_mngr.log_exception(e, level="CRITICAL") # TODO: Be more specific. index += 1 - return self.pile # TODO: Cleanse the pile of None values + final_pile = [] + for p in self.pile: # cleanses the pile from Nones + if p is not None: + final_pile.append(p) + + self.pile = final_pile + return self.pile + + def __iter__(self): + for e in self.pile: + if e: + yield e def lookahead(self, token, index): """ @@ -448,5 +454,5 @@ if __name__ == "__main__": # pragma: no cover print('----------------------------------') # for e in ctx.pile: # rich.inspect(e) - ctx.print_all() - # rich.print(ctx.matched_elements) + # ctx.print_all() + rich.print(ctx.pile)