Fix custom encoding under Python 3.