Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 660e89b

Browse files
committed
Merge: #17443: Fix buffering in IMAP4_stream.
In Python2 Popen uses *FILE objects, which wind up buffering even though subprocess defaults to no buffering. In Python3, subprocess streams really are unbuffered by default, but the imaplib code assumes read is buffered. This patch uses the default buffer size from the io module to get buffered streams from Popen. Much debugging work and patch by Diane Trout. The imap protocol is too complicated to write a test for this simple change with our current level of test infrastructure.
2 parents ed1fe6b + 7889944 commit 660e89b

3 files changed

Lines changed: 8 additions & 0 deletions

File tree

Lib/imaplib.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
import binascii, errno, random, re, socket, subprocess, sys, time, calendar
2626
from datetime import datetime, timezone, timedelta
27+
from io import DEFAULT_BUFFER_SIZE
28+
2729
try:
2830
import ssl
2931
HAVE_SSL = True
@@ -1244,6 +1246,7 @@ def open(self, host = None, port = None):
12441246
self.sock = None
12451247
self.file = None
12461248
self.process = subprocess.Popen(self.command,
1249+
bufsize=DEFAULT_BUFFER_SIZE,
12471250
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
12481251
shell=True, close_fds=True)
12491252
self.writefile = self.process.stdin

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,6 +1236,7 @@ Alberto Trevino
12361236
Matthias Troffaes
12371237
Tom Tromey
12381238
John Tromp
1239+
Diane Trout
12391240
Jason Trowbridge
12401241
Brent Tubbs
12411242
Anthony Tuininga

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,10 @@ Core and Builtins
289289
Library
290290
-------
291291

292+
- Issue #17443: impalib.IMAP4_stream was using the default unbuffered IO
293+
in subprocess, but the imap code assumes buffered IO. In Python2 this
294+
worked by accident. IMAP4_stream now explicitly uses buffered IO.
295+
292296
- Issue #17476: Fixed regression relative to Python2 in undocumented pydoc
293297
'allmethods'; it was missing unbound methods on the class.
294298

0 commit comments

Comments
 (0)