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)
aW1wb3J0IHN5cwoKY2xhc3MgRm9vIChvYmplY3QpOgogICAgCiAgICBkZWYgX19lbnRlcl9fIChzZWxmKToKICAgICAgICBwcmludCgiRW50ZXIiKQogICAgICAgIHJldHVybiAxCiAgICAgICAgCiAgICBkZWYgX19leGl0X18gKHNlbGYsIGV4aXQsIHZhbHVlLCBleGMpOgogICAgICAgIHByaW50KCJFeGl0IikKCm1nciA9IEZvbygpCmV4aXQgPSBGb28uX19leGl0X18KdmFsdWUgPSBGb28uX19lbnRlcl9fKG1ncikKZXhjID0gVHJ1ZQp0cnk6CiAgICB0cnk6CiAgICAgICAgZm9vID0gdmFsdWUKICAgICAgICBwcmludChmb28pCiAgICBleGNlcHQ6CiAgICAgICAgZXhjID0gRmFsc2UKICAgICAgICBpZiBub3QgZXhpdChtZ3IsICpzeXMuZXhjX2luZm8oKSk6CiAgICAgICAgICAgIHJhaXNlCmZpbmFsbHk6CiAgICBpZiBleGM6CiAgICAgICAgZXhpdChtZ3IsIE5vbmUsIE5vbmUsIE5vbmUp