| 256 | _HAVE_EXCEPTION_CHAINING = sys.version_info[0] >= 3 |
| 257 | if _HAVE_EXCEPTION_CHAINING: |
| 258 | def _make_context_fixer(frame_exc): |
| 259 | def _fix_exception_context(new_exc, old_exc): |
| 260 | # Context may not be correct, so find the end of the chain |
| 261 | while 1: |
| 262 | exc_context = new_exc.__context__ |
| 263 | if exc_context is old_exc: |
| 264 | # Context is already set correctly (see issue 20317) |
| 265 | return |
| 266 | if exc_context is None or exc_context is frame_exc: |
| 267 | break |
| 268 | new_exc = exc_context |
| 269 | # Change the end of the chain to point to the exception |
| 270 | # we expect it to reference |
| 271 | new_exc.__context__ = old_exc |
| 272 | return _fix_exception_context |
| 273 | |
| 274 | def _reraise_with_existing_context(exc_details): |
| 275 | try: |