Try locale encoding if stdin encoding is ascii.
Try locale encoding if stdin encoding is ascii.

Starting the Qt console on Python 3, the kernel's stdin ends up with a .encoding of 'ascii' (whereas on Python 2 it is None). Since most platforms can handle a superset of ASCII, we may as well try locale.getpreferredencoding() in this case.

ipython/ipython,ipython/ipython