'Read one entire line from the file.
A trailing newline character is kept in the string (but may be absent
when a file ends with an incomplete line). If the size argument is
present and non-negative, it is a maximum byte count (including the
trailing newline) and an incomplete line may be returned.
An empty string is returned only when EOF is encountered immediately.
Note: Unlike stdio\'s fgets(), the returned string contains null
characters (\'\0\') if they occurred in the input.'

def readline(self, length=None):

    _complain_ifclosed(self.closed)
    if self.buflist:
        self.buf += ''.join(self.buflist)
        self.buflist = []
    i = self.buf.find('\n', self.pos)
    if (i < 0):
        newpos = self.len
    else:
        newpos = (i + 1)
    if ((length is not None) and (length >= 0)):
        if ((self.pos + length) < newpos):
            newpos = (self.pos + length)
    r = self.buf[self.pos:newpos]
    self.pos = newpos
    return r
