This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author martin.panter
Recipients doerwalter, ezio.melotti, fdrake, martin.panter, pitrou, serhiy.storchaka
Date 2015-03-31.22:26:41
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1427840802.1.0.310263959389.issue19100@psf.upfronthosting.co.za>
In-reply-to
Content
Walter: the first line encoding with textio.errors is meant to handle the case where the output stream already has its own permissive error handler set. But anyway I was just trying to point out that it might be better to do the backslash escaping at the text level, and write the escaped text string to the original stream.

Serhiy: thanks for pointing out IDLE’s stdout. It seems the encoding can be set to say ASCII by the locale, yet it still accepts non-ASCII text. But I guess that’s a separate issue.

I haven’t tested the patch, but reading it, I think the there may be a couple of problems:

* Newline handling will be wrong e.g. on windows, where CRLF would be expected. I am not aware of a proper way to determine the newline translation mode of a text stream in arbitrary cases.
* The order of text written directly to stdout and via pprint would get messed up, because pprint would bypass the buffering in the original text stream.
* For encodings that store state, such as “utf-8-sig”, I think you may see an extra signature output, due to creating a new TextIOWrapper. With encoders whose state depends on the actual text, like the "hz" codec, multiplexing ASCII and GB2312 could be a more serious problem.

Issue 15216 is slightly related, and has a patch apparently allowing the encoding and error handler to be changed on a text stream. But I guess it is no good here because you need backwards compatibility with other non-TextIOWrapper streams.
History
Date User Action Args
2015-03-31 22:26:42martin.pantersetrecipients: + martin.panter, fdrake, doerwalter, pitrou, ezio.melotti, serhiy.storchaka
2015-03-31 22:26:42martin.pantersetmessageid: <1427840802.1.0.310263959389.issue19100@psf.upfronthosting.co.za>
2015-03-31 22:26:42martin.panterlinkissue19100 messages
2015-03-31 22:26:41martin.pantercreate