Backport to python 2.4