Python 3 support

This adds Python 3 support.

Work in progress, tests pass, but I didn't test it yet.