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 pitrou
Recipients benjamin.peterson, ezio.melotti, pitrou, stefanholek
Date 2011-11-04.15:06:18
SpamBayes Score 1.6653345e-16
Marked as misclassified No
Message-id <1320419180.24.0.212801305164.issue13342@psf.upfronthosting.co.za>
In-reply-to
Content
> There cannot be a reason input() should be confined to "strict", or can 
> there? ;-)

Actually, there's a good reason: in the non-interactive case, input() simply calls sys.stdin.read(), which doesn't have encoding or errors attributes. You want to override sys.stdin so that it has the right error handler.

However, there is a bug in input() in that it ignores sys.stdin's error handler in interactive mode (where it delegates to the readline library, if present):

>>> import sys, io
>>> sys.stdin = io.TextIOWrapper(sys.stdin.detach(), "ascii", "replace")
>>> sys.stdin.read()
héhé
'h��h��\n'
>>> input()
héhé
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1: ordinal not in range(128)


If you don't mind losing GNU readline functionality, the immediate workaround for you is to use sys.stdin.read() directly.
History
Date User Action Args
2011-11-04 15:06:20pitrousetrecipients: + pitrou, benjamin.peterson, ezio.melotti, stefanholek
2011-11-04 15:06:20pitrousetmessageid: <1320419180.24.0.212801305164.issue13342@psf.upfronthosting.co.za>
2011-11-04 15:06:19pitroulinkissue13342 messages
2011-11-04 15:06:18pitroucreate