'Read a line of text, decode it using this reader\'s encoding,
and return the resulting unicode string.
:param size: The maximum number of bytes to read.  If no
newline is encountered before ``size`` bytes have been read,
then the returned value may not be a complete line of text.
:type size: int'

def readline(self, size=None):

    if (self.linebuffer and (len(self.linebuffer) > 1)):
        line = self.linebuffer.pop(0)
        self._rewind_numchars += len(line)
        return line
    readsize = (size or 72)
    chars = u''
    if self.linebuffer:
        chars += self.linebuffer.pop()
        self.linebuffer = None
    while True:
        startpos = (self.stream.tell() - len(self.bytebuffer))
        new_chars = self._read(readsize)
        if (new_chars and new_chars.endswith(u'\r')):
            new_chars += self._read(1)
        chars += new_chars
        lines = chars.splitlines(True)
        if (len(lines) > 1):
            line = lines[0]
            self.linebuffer = lines[1:]
            self._rewind_numchars = (len(new_chars) - (len(chars) - len(line)))
            self._rewind_checkpoint = startpos
            break
        elif (len(lines) == 1):
            line0withend = lines[0]
            line0withoutend = lines[0].splitlines(False)[0]
            if (line0withend != line0withoutend):
                line = line0withend
                break
        if ((not new_chars) or (size is not None)):
            line = chars
            break
        if (readsize < 8000):
            readsize *= 2
    return line
