Fix Python 3 compatibility

This commit adds compatibility for Python 3.x.
It also have the side-effect of breaking Python 2.4 and older (and may also break 2.5).