Kaydet (Commit) b94e0cde authored tarafından Charles-François Natali's avatar Charles-François Natali

Issue #1441530: In imaplib, use makefile() to wrap the SSL socket to avoid

heap fragmentation and MemoryError with some malloc implementations.
üst 40b41e1f
...@@ -1158,28 +1158,17 @@ else: ...@@ -1158,28 +1158,17 @@ else:
self.port = port self.port = port
self.sock = socket.create_connection((host, port)) self.sock = socket.create_connection((host, port))
self.sslobj = ssl.wrap_socket(self.sock, self.keyfile, self.certfile) self.sslobj = ssl.wrap_socket(self.sock, self.keyfile, self.certfile)
self.file = self.sslobj.makefile('rb')
def read(self, size): def read(self, size):
"""Read 'size' bytes from remote.""" """Read 'size' bytes from remote."""
# sslobj.read() sometimes returns < size bytes return self.file.read(size)
chunks = []
read = 0
while read < size:
data = self.sslobj.read(min(size-read, 16384))
read += len(data)
chunks.append(data)
return ''.join(chunks)
def readline(self): def readline(self):
"""Read line from remote.""" """Read line from remote."""
line = [] return self.file.readline()
while 1:
char = self.sslobj.read(1)
line.append(char)
if char in ("\n", ""): return ''.join(line)
def send(self, data): def send(self, data):
...@@ -1195,6 +1184,7 @@ else: ...@@ -1195,6 +1184,7 @@ else:
def shutdown(self): def shutdown(self):
"""Close I/O established in "open".""" """Close I/O established in "open"."""
self.file.close()
self.sock.close() self.sock.close()
......
...@@ -83,6 +83,9 @@ Core and Builtins ...@@ -83,6 +83,9 @@ Core and Builtins
Library 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 - 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 their encode() method anymore, but continue to call the reset() method if the
final argument is True. final argument is True.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment