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.
Use io instead of codecs
compat.open = io.open
Use .buffer when writing bytes