import sys

class Foo (object):
    
    def __enter__ (self):
        print("Enter")
        return 1
        
    def __exit__ (self, exit, value, exc):
        print("Exit")

mgr = Foo()
exit = Foo.__exit__
value = Foo.__enter__(mgr)
exc = True
try:
    try:
        foo = value
        print(foo)
    except:
        exc = False
        if not exit(mgr, *sys.exc_info()):
            raise
finally:
    if exc:
        exit(mgr, None, None, None)