This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author neologix
Recipients BreamoreBoy, amaury.forgeotdarc, anglocelt, elachuni, marcio, mcicogni, neologix, pitrou, r.david.murray, taukki, trogdorsey, vila
Date 2011-05-21.16:47:56
SpamBayes Score 6.661338e-16
Marked as misclassified No
Message-id <BANLkTik218XCYTh1qHoq+J=fF2NYnXeDwA@mail.gmail.com>
In-reply-to <1305991870.24.0.498705748909.issue1441530@psf.upfronthosting.co.za>
Content
> Patch looks ok. Is 3.x also affected? The I/O stack changed quite a bit in
> 3.x.

I think it's not affected, but I can't reproduce this behaviour with
glibc/eglibc, so don't just take my word for it.
The reason is that in py3k, imaplib uses a buffered reader to read
from the socket (obtained through sock.makefile()), and IIUC, reading
from a buffered reader n bytes will always return n bytes (unless EOF
is encountered or the underlying object is set to non-blocking),
contrarily to reading directly from a socket. So the resizing is done
from the buffered io module, which only grows the result buffer,
freeing the buffers returned by socket's recv() one at a time.

Note that if I'm right, another way to solve this would be to wrap the
SSL socket with a call to makefile, like what's already done for the
non-SSL case (and in py3k). This would also lead to cleaner and
simpler code, because we wouldn't need to handle partial reads
ourself.
That's what the patch attached does.
Note that if I'm correct, then the current py3k imaplib read() method
could also be simplified:

    def read(self, size):
        """Read 'size' bytes from remote."""
        chunks = []
        read = 0
        while read < size:
            data = self.file.read(min(size-read, 4096))
            if not data:
                break
            read += len(data)
            chunks.append(data)
        return b''.join(chunks)

It would also be a bit faster.
But since I can't reproduce this issue, I'd rather make sure it's
correct before making a such change.
Files
File name Uploaded
imaplib_ssl_makefile.diff neologix, 2011-05-21.16:47:56
History
Date User Action Args
2011-05-21 16:47:57neologixsetrecipients: + neologix, mcicogni, amaury.forgeotdarc, pitrou, taukki, vila, elachuni, anglocelt, r.david.murray, marcio, trogdorsey, BreamoreBoy
2011-05-21 16:47:57neologixlinkissue1441530 messages
2011-05-21 16:47:56neologixcreate