'Fetches a next line that ends either with \r or \n.'

def nextline(self):

    linebuf = ''
    linepos = (self.bufpos + self.charpos)
    eol = False
    while 1:
        self.fillbuf()
        if eol:
            c = self.buf[self.charpos]
            if (c == '\n'):
                linebuf += c
                self.charpos += 1
            break
        m = EOL.search(self.buf, self.charpos)
        if m:
            linebuf += self.buf[self.charpos:m.end(0)]
            self.charpos = m.end(0)
            if (linebuf[(-1)] == '\r'):
                eol = True
            else:
                break
        else:
            linebuf += self.buf[self.charpos:]
            self.charpos = len(self.buf)
    return (linepos, linebuf)
