Context manager class to support localcontext(). Sets a copy of the supplied context in __enter__() and restores the previous decimal context in __exit__()
| 3830 | ##### Context class ####################################################### |
| 3831 | |
| 3832 | class _ContextManager(object): |
| 3833 | """Context manager class to support localcontext(). |
| 3834 | |
| 3835 | Sets a copy of the supplied context in __enter__() and restores |
| 3836 | the previous decimal context in __exit__() |
| 3837 | """ |
| 3838 | def __init__(self, new_context): |
| 3839 | self.new_context = new_context.copy() |
| 3840 | def __enter__(self): |
| 3841 | self.saved_context = getcontext() |
| 3842 | setcontext(self.new_context) |
| 3843 | return self.new_context |
| 3844 | def __exit__(self, t, v, tb): |
| 3845 | setcontext(self.saved_context) |
| 3846 | |
| 3847 | class Context(object): |
| 3848 | """Contains the context for a Decimal instance. |