def __exit__(self, exc_type, exc_val, exc_tb): """ Called when exiting the with-block EXAMPLES:: sage: libgap.set_global('FooBar', 1) sage: with libgap.global_context('FooBar', 2): ....: print libgap.get_global('FooBar') 2 sage: libgap.get_global('FooBar') 1 """ libgap.set_global(self._variable, self._old_value) return False
def __enter__(self): """ Called when entering the with-block EXAMPLES:: sage: libgap.set_global('FooBar', 1) sage: with libgap.global_context('FooBar', 2): ....: print libgap.get_global('FooBar') 2 sage: libgap.get_global('FooBar') 1 """ self._old_value = libgap.get_global(self._variable) libgap.set_global(self._variable, self._new_value)