fix for python 3.2 (no 'nested' function nor 'ExitStack')