Fix compatibility with pre-2.7.x python

Please, merge it if you want the tools works on python 2.6.x. This PR also contains the commit fixing list of imports.