make python3 compatible

I used six to make it work with python 3. I tested on 3.4 only.