Upgrade for python3

Use 2to3 at first.

Then run it in python. Fixed bugs.