Port to Python 3. Requires >=3.3, 2.x still supported.

Tests are passing.