creating a context manager for a python with statement