Tweaks to back-port code from Python 3.3 to 2.8