Python 3 support library compatibility refactoring