Clean up python2/3 compatibility.

@dirk-thomas @wjwwood please review