Backport to python 2.4
Merge pull request #1487 from nouiz/py2.4

Backport to python 2.4