[Python-ideas] changing sys.stdout encoding (original) (raw)
Amaury Forgeot d'Arc amauryfa at gmail.com
Tue Jun 5 23:22:27 CEST 2012
- Previous message: [Python-ideas] changing sys.stdout encoding
- Next message: [Python-ideas] changing sys.stdout encoding
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
2012/6/5 Stephen J. Turnbull <stephen at xemacs.org>
I wouldn't object to a method with the semantics of reinitialization, but it should have a name implying reinitialization. It probably should also error if the stream is open and has been written to.
What do you think of the following method TextIOWrapper.reset_encoding? (the assert statements should certainly be replaced by some IOError)
:: def reset_encoding(self, encoding, errors='strict'): if self._decoder: # No decoded chars awaiting read assert self._decoded_chars_used == len(self._decoded_chars) # Nothing in the input buffer buf, flag = self._decoder.getstate() assert buf == b'' if self._encoder: # Nothing in the output buffer buf = self._encoder.encode('', final=True) assert buf == b'' # Reset the decoders self._decoder = None self._encoder = None # Now change the encoding self._encoding = encoding self._errors = errors
-- Amaury Forgeot d'Arc -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-ideas/attachments/20120605/457ab1b7/attachment.html>
- Previous message: [Python-ideas] changing sys.stdout encoding
- Next message: [Python-ideas] changing sys.stdout encoding
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]