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.
This commit is contained in:
R David Murray 2013-03-19 13:56:01 -04:00
commit 7889944b83
3 changed files with 8 additions and 0 deletions

View File

@ -24,6 +24,8 @@ __version__ = "2.58"
import binascii, errno, random, re, socket, subprocess, sys, time, calendar import binascii, errno, random, re, socket, subprocess, sys, time, calendar
from datetime import datetime, timezone, timedelta from datetime import datetime, timezone, timedelta
from io import DEFAULT_BUFFER_SIZE
try: try:
import ssl import ssl
HAVE_SSL = True HAVE_SSL = True
@ -1244,6 +1246,7 @@ class IMAP4_stream(IMAP4):
self.sock = None self.sock = None
self.file = None self.file = None
self.process = subprocess.Popen(self.command, self.process = subprocess.Popen(self.command,
bufsize=DEFAULT_BUFFER_SIZE,
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
shell=True, close_fds=True) shell=True, close_fds=True)
self.writefile = self.process.stdin self.writefile = self.process.stdin

View File

@ -1216,6 +1216,7 @@ Alberto Trevino
Matthias Troffaes Matthias Troffaes
Tom Tromey Tom Tromey
John Tromp John Tromp
Diane Trout
Jason Trowbridge Jason Trowbridge
Brent Tubbs Brent Tubbs
Anthony Tuininga Anthony Tuininga

View File

@ -193,6 +193,10 @@ Core and Builtins
Library Library
------- -------
- Issue #17443: impalib.IMAP4_stream was using the default unbuffered IO
in subprocess, but the imap code assumes buffered IO. In Python2 this
worked by accident. IMAP4_stream now explicitly uses buffered IO.
- Issue #17476: Fixed regression relative to Python2 in undocumented pydoc - Issue #17476: Fixed regression relative to Python2 in undocumented pydoc
'allmethods'; it was missing unbound methods on the class. 'allmethods'; it was missing unbound methods on the class.