Python 3 compatibility fixes.

Hello, these small changes will add support for Python 3 while still being compatible with 2.6 and 2.7.