Backport r71967 changes from py3k to trunk.