From d70878831c67c3b2d76ab304edadfaed3cfbb980 Mon Sep 17 00:00:00 2001 From: Robey Pointer Date: Sun, 30 Dec 2007 16:32:59 -0800 Subject: [PATCH] [project @ robey@lag.net-20071231003259-xwwescnkvb3e6vxc] 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. --- paramiko/file.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/paramiko/file.py b/paramiko/file.py index c5ec5c4..7db4401 100644 --- a/paramiko/file.py +++ b/paramiko/file.py @@ -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):