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