Move Python 2/3 compat helpers to its own module