[Python-checkins] r59363 - peps/trunk/pep-3116.txt

guido.van.rossum python-checkins at python.org
Wed Dec 5 20:18:28 CET 2007


Author: guido.van.rossum
Date: Wed Dec  5 20:18:28 2007
New Revision: 59363

Modified:
   peps/trunk/pep-3116.txt
Log:
Add line_buffering to TextIOWrapper().


Modified: peps/trunk/pep-3116.txt
==============================================================================
--- peps/trunk/pep-3116.txt	(original)
+++ peps/trunk/pep-3116.txt	Wed Dec  5 20:18:28 2007
@@ -339,7 +339,8 @@
 ``BufferedIOBase`` object.  Its initializer has the following
 signature:
 
-    ``.__init__(self, buffer, encoding=None, errors=None, newline=None)``
+    ``.__init__(self, buffer, encoding=None, errors=None, newline=None,
+                line_buffering=False)``
 
         ``buffer`` is a reference to the ``BufferedIOBase`` object to
         be wrapped with the ``TextIOWrapper``.
@@ -377,6 +378,12 @@
           guiding translation are different for output than for
           input.)
 
+        ``line_buffering``, if True, causes ``write()`` calls to imply
+        a ``flush()`` if the string written contains at least one
+        ``'\n'`` or ``'\r'`` character.  This is set by ``open()``
+        when it detects that the underlying stream is a TTY device,
+        or when a ``buffering`` argument of ``1`` is passed.
+
         Further notes on the ``newline`` parameter:
 
         * ``'\r'`` support is still needed for some OSX applications
@@ -487,7 +494,8 @@
             raise ValueError("binary modes doesn't take a newline arg")
         # XXX Need to spec the signature for FileIO()
         raw = FileIO(filename, mode)
-        if buffering is None:
+        line_buffering = (buffering == 1 or buffering is None and raw.isatty())
+        if line_buffering or buffering is None:
             buffering = 8*1024  # International standard buffer size
             # XXX Try setting it to fstat().st_blksize
         if buffering < 0:
@@ -506,7 +514,7 @@
         if binary:
             return buffer
         assert text
-        return TextIOWrapper(buffer, encoding, errors, newline)
+        return TextIOWrapper(buffer, encoding, errors, newline, line_buffering)
 
 
 Copyright


More information about the Python-checkins mailing list