Message147010
> 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. |
|
Date |
User |
Action |
Args |
2011-11-04 15:06:20 | pitrou | set | recipients:
+ pitrou, benjamin.peterson, ezio.melotti, stefanholek |
2011-11-04 15:06:20 | pitrou | set | messageid: <1320419180.24.0.212801305164.issue13342@psf.upfronthosting.co.za> |
2011-11-04 15:06:19 | pitrou | link | issue13342 messages |
2011-11-04 15:06:18 | pitrou | create | |
|