diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2014-05-08 22:24:50 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2014-05-08 22:24:50 (GMT) |
commit | c644e7c39f7adf0ed783e128b0278665133bf523 (patch) | |
tree | 85a2c3c546b5b9f3c189ef45d4c6b5b932af7d60 /Modules/_io/textio.c | |
parent | a83ade1d60a18d7cf2f96f9e059947a770c491ee (diff) | |
download | cpython-c644e7c39f7adf0ed783e128b0278665133bf523.zip cpython-c644e7c39f7adf0ed783e128b0278665133bf523.tar.gz cpython-c644e7c39f7adf0ed783e128b0278665133bf523.tar.bz2 |
Issue #21396: Fix TextIOWrapper(..., write_through=True) to not force a flush() on the underlying binary stream.
Patch by akira.
Diffstat (limited to 'Modules/_io/textio.c')
-rw-r--r-- | Modules/_io/textio.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c index 5739bc4..ba5789d 100644 --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -1297,7 +1297,7 @@ textiowrapper_write(textio *self, PyObject *args) PyObject *b; Py_ssize_t textlen; int haslf = 0; - int needflush = 0; + int needflush = 0, text_needflush = 0; CHECK_INITIALIZED(self); @@ -1331,8 +1331,8 @@ textiowrapper_write(textio *self, PyObject *args) } if (self->write_through) - needflush = 1; - else if (self->line_buffering && + text_needflush = 1; + if (self->line_buffering && (haslf || PyUnicode_FindChar(text, '\r', 0, PyUnicode_GET_LENGTH(text), 1) != -1)) needflush = 1; @@ -1363,7 +1363,8 @@ textiowrapper_write(textio *self, PyObject *args) } self->pending_bytes_count += PyBytes_GET_SIZE(b); Py_DECREF(b); - if (self->pending_bytes_count > self->chunk_size || needflush) { + if (self->pending_bytes_count > self->chunk_size || needflush || + text_needflush) { if (_textiowrapper_writeflush(self) < 0) return NULL; } |