Python3 fixes

Various fixes required for Python3 compatibility.

Notably the unittests now work in Python3