Add support for Python 3

These patches add support for Python 3. Tested with Python 2.6, 2.7, 3.2, 3.3, and 3.4.