Improve Python 3.x compatibility

Mechanical translation of deprecated constructs
to 3.x compatible variants.

Change-Id: I4988d0ac656903e0d0320aaa8361d4eeb774a0f9
Merge "Improve Python 3.x compatibility"