tools: fix Python 3.X compatibility issues