From c458c793d55df76e88de9f43d7de93b95e2ea34a Mon Sep 17 00:00:00 2001 From: miyuchina Date: Mon, 8 Jan 2018 20:54:55 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=8E=20FileWrapper.peek=20returns=20Non?= =?UTF-8?q?e=20when=20out=20of=20elements?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mistletoe/block_token.py | 9 ++++----- mistletoe/block_tokenizer.py | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/mistletoe/block_token.py b/mistletoe/block_token.py index 4d17ff0a..854c2c8e 100644 --- a/mistletoe/block_token.py +++ b/mistletoe/block_token.py @@ -431,11 +431,10 @@ def start(cls, line): @classmethod def read(cls, lines): line_buffer = [] - try: - while cls._is_legal(lines.peek()) and lines.peek() != '\n': - line_buffer.append(next(lines)) - except StopIteration: - pass + while (lines.peek() is not None + and cls._is_legal(lines.peek()) + and lines.peek() != '\n'): + line_buffer.append(next(lines)) return line_buffer diff --git a/mistletoe/block_tokenizer.py b/mistletoe/block_tokenizer.py index c8ddf9ae..68d64247 100644 --- a/mistletoe/block_tokenizer.py +++ b/mistletoe/block_tokenizer.py @@ -36,7 +36,7 @@ def reset(self): def peek(self): if self._index + 1 < len(self.lines): return self.lines[self._index+1] - raise StopIteration + return None def tokenize(iterable, token_types, root=None):