Update to python 3 syntax using 3to2.
Fixed some functions to use decode() to local encoding for python 3.