Port to Python3.

These changes should provide compatibility with Python 3.3. Still seems okay on Python 2.7.