Backported to Python 2.