From 61ad46759299378ebf0c21c55f1cb9b60afba280 Mon Sep 17 00:00:00 2001 From: Matthew Wardrop Date: Wed, 8 Aug 2018 13:25:03 -0700 Subject: [PATCH] Stop iteration over file when file is empty or exhausted. --- omniduct/filesystems/base.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/omniduct/filesystems/base.py b/omniduct/filesystems/base.py index 8058cd4..745cc2f 100644 --- a/omniduct/filesystems/base.py +++ b/omniduct/filesystems/base.py @@ -729,6 +729,10 @@ def flush(self): def isatty(self): return self.__io_buffer.isatty() + @property + def newlines(self): + return '\n' # TODO: Support non-Unix newlines? + def read(self, size=-1): if not self.readable: raise io.UnsupportedOperation("File not open for reading.") @@ -760,7 +764,11 @@ def __iter__(self): return self def __next__(self): - return self.readline() + line = self.readline() + if line: + return line + else: + raise StopIteration next = __next__ # Python 2