WIP py3k support

cherry picked from @warrd