Skip to content

Commit 994815e

Browse files
committed
Issue python#22413: Merge StringIO doc from 3.4 into 3.5
2 parents 3cae757 + cfad543 commit 994815e

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

Doc/library/io.rst

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -889,17 +889,25 @@ Text I/O
889889
An in-memory stream for text I/O. The text buffer is discarded when the
890890
:meth:`~IOBase.close` method is called.
891891

892-
The initial value of the buffer (an empty string by default) can be set by
893-
providing *initial_value*. The *newline* argument works like that of
894-
:class:`TextIOWrapper`. The default is to consider only ``\n`` characters
895-
as end of lines and to do no newline translation.
892+
The initial value of the buffer can be set by providing *initial_value*.
893+
If newline translation is enabled, newlines will be encoded as if by
894+
:meth:`~TextIOBase.write`. The stream is positioned at the start of
895+
the buffer.
896+
897+
The *newline* argument works like that of :class:`TextIOWrapper`.
898+
The default is to consider only ``\n`` characters as ends of lines and
899+
to do no newline translation. If *newline* is set to ``None``,
900+
newlines are written as ``\n`` on all platforms, but universal
901+
newline decoding is still performed when reading.
896902

897903
:class:`StringIO` provides this method in addition to those from
898904
:class:`TextIOBase` and its parents:
899905

900906
.. method:: getvalue()
901907

902908
Return a ``str`` containing the entire contents of the buffer.
909+
Newlines are decoded as if by :meth:`~TextIOBase.read`, although
910+
the stream position is not changed.
903911

904912
Example usage::
905913

Modules/_io/_iomodule.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,12 @@ extern PyObject *_PyIncrementalNewlineDecoder_decode(
5252
which can be safely put aside until another search.
5353
5454
NOTE: for performance reasons, `end` must point to a NUL character ('\0').
55-
Otherwise, the function will scan further and return garbage. */
55+
Otherwise, the function will scan further and return garbage.
56+
57+
There are three modes, in order of priority:
58+
* translated: Only find \n (assume newlines already translated)
59+
* universal: Use universal newlines algorithm
60+
* Otherwise, the line ending is specified by readnl, a str object */
5661
extern Py_ssize_t _PyIO_find_line_ending(
5762
int translated, int universal, PyObject *readnl,
5863
int kind, char *start, char *end, Py_ssize_t *consumed);

0 commit comments

Comments
 (0)