Extracted Python 2/3 specific code into the portability module