Support Python 3

Code after initial 2to3 run, no other custom changes