Apply patch provided on the ActiveState forum by RobSeegel.