Fix python3 compatibility.
Patch by GUIpsp implemented. Code now works with Python 3.3 and no
external libs