be more explicit about setting buffering options, and make the default
be "unbuffered", because with buffering on, writes are buffered, which can
be very confusing over ssh and usually not what you want.
This commit is contained in:
Robey Pointer 2007-12-30 16:32:59 -08:00
parent a3128c63de
commit d70878831c
1 changed files with 11 additions and 0 deletions

View File

@ -392,6 +392,12 @@ class BufferedFile (object):
"""
Subclasses call this method to initialize the BufferedFile.
"""
# set bufsize in any event, because it's used for readline().
self._bufsize = self._DEFAULT_BUFSIZE
if bufsize < 0:
# do no buffering by default, because otherwise writes will get
# buffered in a way that will probably confuse people.
bufsize = 0
if bufsize == 1:
# apparently, line buffering only affects writes. reads are only
# buffered if you call readline (directly or indirectly: iterating
@ -400,6 +406,11 @@ class BufferedFile (object):
elif bufsize > 1:
self._bufsize = bufsize
self._flags |= self.FLAG_BUFFERED
self._flags &= ~self.FLAG_LINE_BUFFERED
elif bufsize == 0:
# unbuffered
self._flags &= ~(self.FLAG_BUFFERED | self.FLAG_LINE_BUFFERED)
if ('r' in mode) or ('+' in mode):
self._flags |= self.FLAG_READ
if ('w' in mode) or ('+' in mode):