[issue1441530] socket read() can cause MemoryError in Windows
Anthony Lenton
report at bugs.python.org
Fri Sep 12 03:18:06 CEST 2008
Anthony Lenton <antoniolenton at gmail.com> added the comment:
It's probably just a typo from copying from an editor, but there is a
bug in the workaround. It should be:
maxRead = 1000000
class MySSL (imaplib.IMAP4_SSL):
def read (self, n):
#print "..Attempting to read %d bytes" % n
if n <= maxRead:
return imaplib.IMAP4_SSL.read (self, n)
else:
soFar = 0
result = ""
while soFar < n:
thisFragmentSize = min(maxRead, n-soFar)
#print "..Reading fragment size %s" % thisFragmentSize
fragment =\
imaplib.IMAP4_SSL.read (self, thisFragmentSize)
result += fragment
soFar += thisFragmentSize # only a few, so not a tragic o/head
return result
(With one less level of indentation in the last line).
Apart from that, the fix works wonderfully.
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue1441530>
_______________________________________
More information about the Python-bugs-list
mailing list