Backport of eaeea6f947 from master
eaeea6f947
Should be unneeded with Python 2.7 and up. Added some unicode_literals along the way.