(self, *exc_details)
| 389 | return self |
| 390 | |
| 391 | def __exit__(self, *exc_details): |
| 392 | received_exc = exc_details[0] is not None |
| 393 | |
| 394 | # We manipulate the exception state so it behaves as though |
| 395 | # we were actually nesting multiple with statements |
| 396 | frame_exc = sys.exc_info()[1] |
| 397 | _fix_exception_context = _make_context_fixer(frame_exc) |
| 398 | |
| 399 | # Callbacks are invoked in LIFO order to match the behaviour of |
| 400 | # nested context managers |
| 401 | suppressed_exc = False |
| 402 | pending_raise = False |
| 403 | while self._exit_callbacks: |
| 404 | cb = self._exit_callbacks.pop() |
| 405 | try: |
| 406 | if cb(*exc_details): |
| 407 | suppressed_exc = True |
| 408 | pending_raise = False |
| 409 | exc_details = (None, None, None) |
| 410 | except: |
| 411 | new_exc_details = sys.exc_info() |
| 412 | # simulate the stack of exceptions by setting the context |
| 413 | _fix_exception_context(new_exc_details[1], exc_details[1]) |
| 414 | pending_raise = True |
| 415 | exc_details = new_exc_details |
| 416 | if pending_raise: |
| 417 | _reraise_with_existing_context(exc_details) |
| 418 | return received_exc and suppressed_exc |
| 419 | |
| 420 | # Preserve backwards compatibility |
| 421 | class ContextStack(ExitStack): |
no test coverage detected