Remove Python 2.4-incompatible 'with' statement (fix #5044)