mirror of
https://github.com/python/cpython.git
synced 2025-11-03 03:22:27 +00:00
Issue #22413: Merge StringIO doc from 3.5
This commit is contained in:
commit
a6d5038226
3 changed files with 20 additions and 9 deletions
|
|
@ -889,10 +889,16 @@ Text I/O
|
||||||
An in-memory stream for text I/O. The text buffer is discarded when the
|
An in-memory stream for text I/O. The text buffer is discarded when the
|
||||||
:meth:`~IOBase.close` method is called.
|
:meth:`~IOBase.close` method is called.
|
||||||
|
|
||||||
The initial value of the buffer (an empty string by default) can be set by
|
The initial value of the buffer can be set by providing *initial_value*.
|
||||||
providing *initial_value*. The *newline* argument works like that of
|
If newline translation is enabled, newlines will be encoded as if by
|
||||||
:class:`TextIOWrapper`. The default is to consider only ``\n`` characters
|
:meth:`~TextIOBase.write`. The stream is positioned at the start of
|
||||||
as end of lines and to do no newline translation.
|
the buffer.
|
||||||
|
|
||||||
|
The *newline* argument works like that of :class:`TextIOWrapper`.
|
||||||
|
The default is to consider only ``\n`` characters as ends of lines and
|
||||||
|
to do no newline translation. If *newline* is set to ``None``,
|
||||||
|
newlines are written as ``\n`` on all platforms, but universal
|
||||||
|
newline decoding is still performed when reading.
|
||||||
|
|
||||||
:class:`StringIO` provides this method in addition to those from
|
:class:`StringIO` provides this method in addition to those from
|
||||||
:class:`TextIOBase` and its parents:
|
:class:`TextIOBase` and its parents:
|
||||||
|
|
@ -900,6 +906,8 @@ Text I/O
|
||||||
.. method:: getvalue()
|
.. method:: getvalue()
|
||||||
|
|
||||||
Return a ``str`` containing the entire contents of the buffer.
|
Return a ``str`` containing the entire contents of the buffer.
|
||||||
|
Newlines are decoded as if by :meth:`~TextIOBase.read`, although
|
||||||
|
the stream position is not changed.
|
||||||
|
|
||||||
Example usage::
|
Example usage::
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,12 @@ extern PyObject *_PyIncrementalNewlineDecoder_decode(
|
||||||
which can be safely put aside until another search.
|
which can be safely put aside until another search.
|
||||||
|
|
||||||
NOTE: for performance reasons, `end` must point to a NUL character ('\0').
|
NOTE: for performance reasons, `end` must point to a NUL character ('\0').
|
||||||
Otherwise, the function will scan further and return garbage. */
|
Otherwise, the function will scan further and return garbage.
|
||||||
|
|
||||||
|
There are three modes, in order of priority:
|
||||||
|
* translated: Only find \n (assume newlines already translated)
|
||||||
|
* universal: Use universal newlines algorithm
|
||||||
|
* Otherwise, the line ending is specified by readnl, a str object */
|
||||||
extern Py_ssize_t _PyIO_find_line_ending(
|
extern Py_ssize_t _PyIO_find_line_ending(
|
||||||
int translated, int universal, PyObject *readnl,
|
int translated, int universal, PyObject *readnl,
|
||||||
int kind, char *start, char *end, Py_ssize_t *consumed);
|
int kind, char *start, char *end, Py_ssize_t *consumed);
|
||||||
|
|
|
||||||
|
|
@ -696,10 +696,8 @@ _io_StringIO___init___impl(stringio *self, PyObject *value,
|
||||||
char *newline = "\n";
|
char *newline = "\n";
|
||||||
Py_ssize_t value_len;
|
Py_ssize_t value_len;
|
||||||
|
|
||||||
/* Parse the newline argument. This used to be done with the 'z'
|
/* Parse the newline argument. We only want to allow unicode objects or
|
||||||
specifier, however this allowed any object with the buffer interface to
|
None. */
|
||||||
be converted. Thus we have to parse it manually since we only want to
|
|
||||||
allow unicode objects or None. */
|
|
||||||
if (newline_obj == Py_None) {
|
if (newline_obj == Py_None) {
|
||||||
newline = NULL;
|
newline = NULL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue