"""
Simple abstraction on top of a file that is read line by line.
"""

import sys

class LineBasedDocument:

    def __init__(self, stream):
        self._stream = stream
        self._at_end = False
        self.advance()

    def advance(self):
        try:
            self._current_line = next(self._stream)
        except StopIteration:
            self._at_end = True

    def current(self):
        if self._at_end:
            raise StopIteration()
        return self._current_line

    def exhausted(self):
        return self._at_end
