Update to support python3.

I have not tested these changes with python2 but I don't think there is anything which should cause a problem.