Add line_buffering to TextIOWrapper().
This commit is contained in:
parent
e04321d079
commit
3a6f48c056
14
pep-3116.txt
14
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
|
||||
|
|
Loading…
Reference in New Issue