Add minimal changes to support Python 2.4.

Fair warning: Support for Python 2.4 may be dropped at any time. But as long as the changes are
that minimal and have no significant side-effects we can keep up the compatibility.