PEP8: W191 indentation contains tabs
Py26: with doesn't support multiple contexts

Unfortunately with does not support multiple contexts in Python 2.6 see
http://stackoverflow.com/a/12141070/2167584

So converted this to nested with statements which should work on all
supported Python versions.