Python 3.x compatibility fixes

Mechanical translation of the easy-to-fix Python 2.x->3.x
compatibility issues. Should work with all Python versions
>= 2.6.

Change-Id: I693ff5d72b2db8d9d3a3347f70f22290897e9cff
Merge "Python 3.x compatibility fixes"