Context manager class to support localcontext(). Sets a copy of the supplied context in __enter__() and restores the previous decimal context in __exit__()
| 3866 | ##### Context class ####################################################### |
| 3867 | |
| 3868 | class _ContextManager(object): |
| 3869 | """Context manager class to support localcontext(). |
| 3870 | |
| 3871 | Sets a copy of the supplied context in __enter__() and restores |
| 3872 | the previous decimal context in __exit__() |
| 3873 | """ |
| 3874 | def __init__(self, new_context): |
| 3875 | self.new_context = new_context.copy() |
| 3876 | def __enter__(self): |
| 3877 | self.saved_context = getcontext() |
| 3878 | setcontext(self.new_context) |
| 3879 | return self.new_context |
| 3880 | def __exit__(self, t, v, tb): |
| 3881 | setcontext(self.saved_context) |
| 3882 | |
| 3883 | class Context(object): |
| 3884 | """Contains the context for a Decimal instance. |