Reconfigure the text stream with new parameters. This also flushes the stream.
(self, *,
encoding=None, errors=None, newline=Ellipsis,
line_buffering=None, write_through=None)
| 2165 | return self._buffer |
| 2166 | |
| 2167 | def reconfigure(self, *, |
| 2168 | encoding=None, errors=None, newline=Ellipsis, |
| 2169 | line_buffering=None, write_through=None): |
| 2170 | """Reconfigure the text stream with new parameters. |
| 2171 | |
| 2172 | This also flushes the stream. |
| 2173 | """ |
| 2174 | if (self._decoder is not None |
| 2175 | and (encoding is not None or errors is not None |
| 2176 | or newline is not Ellipsis)): |
| 2177 | raise UnsupportedOperation( |
| 2178 | "It is not possible to set the encoding or newline of stream " |
| 2179 | "after the first read") |
| 2180 | |
| 2181 | if errors is None: |
| 2182 | if encoding is None: |
| 2183 | errors = self._errors |
| 2184 | else: |
| 2185 | errors = 'strict' |
| 2186 | elif not isinstance(errors, str): |
| 2187 | raise TypeError("invalid errors: %r" % errors) |
| 2188 | |
| 2189 | if encoding is None: |
| 2190 | encoding = self._encoding |
| 2191 | else: |
| 2192 | if not isinstance(encoding, str): |
| 2193 | raise TypeError("invalid encoding: %r" % encoding) |
| 2194 | if encoding == "locale": |
| 2195 | encoding = self._get_locale_encoding() |
| 2196 | |
| 2197 | if newline is Ellipsis: |
| 2198 | newline = self._readnl |
| 2199 | self._check_newline(newline) |
| 2200 | |
| 2201 | if line_buffering is None: |
| 2202 | line_buffering = self.line_buffering |
| 2203 | if write_through is None: |
| 2204 | write_through = self.write_through |
| 2205 | |
| 2206 | self.flush() |
| 2207 | self._configure(encoding, errors, newline, |
| 2208 | line_buffering, write_through) |
| 2209 | |
| 2210 | def seekable(self): |
| 2211 | if self.closed: |