summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles-François Natali <neologix@free.fr>2011-05-24 23:10:54 +0200
committerCharles-François Natali <neologix@free.fr>2011-05-24 23:10:54 +0200
commit8cee40538bee0a7c92ed6cfee095316e9eb8f2c6 (patch)
treeadc218f258f5d3555fa50a3e60c3451deda8077d
parent3c15827acb180e89136699d5503e72308cfa81f0 (diff)
downloadcpython-8cee40538bee0a7c92ed6cfee095316e9eb8f2c6.tar.gz
Issue #1441530: In imaplib, use makefile() to wrap the SSL socket to avoid
heap fragmentation and MemoryError with some malloc implementations.
-rw-r--r--Lib/imaplib.py18
-rw-r--r--Misc/NEWS3
2 files changed, 7 insertions, 14 deletions
diff --git a/Lib/imaplib.py b/Lib/imaplib.py
index 5693191185..c576927a8b 100644
--- a/Lib/imaplib.py
+++ b/Lib/imaplib.py
@@ -1158,28 +1158,17 @@ else:
self.port = port
self.sock = socket.create_connection((host, port))
self.sslobj = ssl.wrap_socket(self.sock, self.keyfile, self.certfile)
+ self.file = self.sslobj.makefile('rb')
def read(self, size):
"""Read 'size' bytes from remote."""
- # sslobj.read() sometimes returns < size bytes
- chunks = []
- read = 0
- while read < size:
- data = self.sslobj.read(min(size-read, 16384))
- read += len(data)
- chunks.append(data)
-
- return ''.join(chunks)
+ return self.file.read(size)
def readline(self):
"""Read line from remote."""
- line = []
- while 1:
- char = self.sslobj.read(1)
- line.append(char)
- if char in ("\n", ""): return ''.join(line)
+ return self.file.readline()
def send(self, data):
@@ -1195,6 +1184,7 @@ else:
def shutdown(self):
"""Close I/O established in "open"."""
+ self.file.close()
self.sock.close()
diff --git a/Misc/NEWS b/Misc/NEWS
index 3d6815fa37..6801fd7084 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -83,6 +83,9 @@ Core and Builtins
Library
-------
+- Issue #1441530: In imaplib, use makefile() to wrap the SSL socket to avoid
+ heap fragmentation and MemoryError with some malloc implementations.
+
- Issue #12100: Don't reset incremental encoders of CJK codecs at each call to
their encode() method anymore, but continue to call the reset() method if the
final argument is True.