Replace encoding override with improved stdio wrappers; use unicode_literals

This is a further development of our Python 3.3 migration strategy, most importantly Unicode handling.

    - Use "from __future__ import unicode_literals" everywhere.
    - Use "sys.stdin = io.open(sys.stdin.fileno(), encoding=...)". This makes sys.stdin behave like it does on Python 3.3, producing unicode without having to rely on hacks, implicit coercion, or external configuration to fix the Python encoding.
    - Replace sys.stdout and sys.stderr using a subclass of io.TextIOWrapper. This subclass makes sys.stdout and sys.stderr accept Unicode text as they do on Python 3, but if non-Unicode input is given to .write(), it will try to cast it to Unicode. This provides backward compatibility, and is necessary to make errors show up on sys.stderr on Python 2.
    - Don't wrap the streams more than once.
    - Replace raw_input() with a shim on Python 2, since it doesn't know how to flush the wrapped stdout buffer before waiting for stdin.

Squashed commit of the following:

commit 40248fa95179da4262713164b0cbb9ca5db59087
Author: Andrey Kislyuk <kislyuk@gmail.com>
Date:   Tue Apr 1 09:48:53 2014 -0700

    Fix failing test

commit 4b972e418627d414567775810231ec5b25e5510e
Author: Andrey Kislyuk <kislyuk@gmail.com>
Date:   Mon Mar 31 13:19:57 2014 -0700

    fix broken merge

commit 5c016c54f3ddf3412cb62b47f0646750b7806919
Author: Andrey Kislyuk <kislyuk@gmail.com>
Date:   Sat Mar 29 14:17:02 2014 -0700

    Use .buffer when writing bytes

commit de6aeada5d183592beee14a6a32576368bbf48dc
Author: Andrey Kislyuk <kislyuk@gmail.com>
Date:   Sat Mar 29 13:54:08 2014 -0700

    compat.open = io.open

commit 3e4e07850218c9c399fcf0e632aeba1bc256159a
Author: Andrey Kislyuk <kislyuk@gmail.com>
Date:   Sat Mar 29 13:32:51 2014 -0700

    Use io instead of codecs

commit df517b1e3090896015d1d04cf76ff44434ffaa5d
Author: Andrey Kislyuk <kislyuk@gmail.com>
Date:   Sat Mar 22 18:08:10 2014 -0700

    Use improved stdio wrappers and input shim; use unicode_literals

    In this branch, we will finalize development of our Python 3.3 migration strategy, most importantly Unicode handling.

    - Use "from __future__ import unicode_literals" everywhere.
    - Use "sys.stdin = io.open(sys.stdin.fileno(), encoding=...)". This makes sys.stdin behave like it does on Python 3.3, producing unicode without having to rely on hacks, implicit coercion, or external configuration to fix the Python encoding.
    - Replace sys.stdout and sys.stderr using a subclass of io.TextIOWrapper. This subclass makes sys.stdout and sys.stderr accept Unicode text as they do on Python 3, but if non-Unicode input is given to .write(), it will try to cast it to Unicode. This provides backward compatibility, and is necessary to make errors show up on sys.stderr on Python 2.
    - Don't wrap the streams more than once.
    - Replace raw_input() with a shim on Python 2, since it doesn't know how to flush the wrapped stdout buffer before waiting for stdin.