From 3a6f48c0564116eeff6d18c7c20f7e4aa3290fb2 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Wed, 5 Dec 2007 19:18:28 +0000 Subject: [PATCH] Add line_buffering to TextIOWrapper(). --- pep-3116.txt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pep-3116.txt b/pep-3116.txt index b67f29234..57e8d0f3a 100644 --- a/pep-3116.txt +++ b/pep-3116.txt @@ -339,7 +339,8 @@ object. Each ``TextIOWrapper`` object has a property named ``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 @@ signature: 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 @@ pseudo-code:: 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 @@ pseudo-code:: if binary: return buffer assert text - return TextIOWrapper(buffer, encoding, errors, newline) + return TextIOWrapper(buffer, encoding, errors, newline, line_buffering) Copyright