diff options
author | Antoine Pitrou <pitrou@free.fr> | 2017-06-03 10:32:28 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-03 10:32:28 (GMT) |
commit | 3c2817b6884a5fcf792197203f3c26b157210607 (patch) | |
tree | 36f32bf5581fb14a60257630be600cc1077a260c /Lib/_pyio.py | |
parent | ae8750bca8234a9af9382b9d7e457b57f810ad64 (diff) | |
download | cpython-3c2817b6884a5fcf792197203f3c26b157210607.zip cpython-3c2817b6884a5fcf792197203f3c26b157210607.tar.gz cpython-3c2817b6884a5fcf792197203f3c26b157210607.tar.bz2 |
Fix bpo-30526: Add TextIOWrapper.reconfigure() and a TextIOWrapper.write_through attribute (#1922)
* Fix bpo-30526: Add TextIOWrapper.reconfigure()
* Apply Nick's improved wording
* Update Misc/NEWS
Diffstat (limited to 'Lib/_pyio.py')
-rw-r--r-- | Lib/_pyio.py | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/Lib/_pyio.py b/Lib/_pyio.py index 5dfc1f0..d50230d 100644 --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -1943,7 +1943,6 @@ class TextIOWrapper(TextIOBase): raise ValueError("invalid errors: %r" % errors) self._buffer = buffer - self._line_buffering = line_buffering self._encoding = encoding self._errors = errors self._readuniversal = not newline @@ -1969,6 +1968,12 @@ class TextIOWrapper(TextIOBase): # Sometimes the encoder doesn't exist pass + self._configure(line_buffering, write_through) + + def _configure(self, line_buffering=False, write_through=False): + self._line_buffering = line_buffering + self._write_through = write_through + # self._snapshot is either None, or a tuple (dec_flags, next_input) # where dec_flags is the second (integer) item of the decoder state # and next_input is the chunk of input bytes that comes next after the @@ -2008,9 +2013,25 @@ class TextIOWrapper(TextIOBase): return self._line_buffering @property + def write_through(self): + return self._write_through + + @property def buffer(self): return self._buffer + def reconfigure(self, *, line_buffering=None, write_through=None): + """Reconfigure the text stream with new parameters. + + This also flushes the stream. + """ + if line_buffering is None: + line_buffering = self.line_buffering + if write_through is None: + write_through = self.write_through + self.flush() + self._configure(line_buffering, write_through) + def seekable(self): if self.closed: raise ValueError("I/O operation on closed file.") |