Upgrade code for Python 3 compatibility (but library is not compatible)