# Path: tornado/util.py
# def raise_exc_info(exc_info):
#     """Re-raise an exception (with original traceback) from an exc_info tuple.
# 
#     The argument is a ``(type, value, traceback)`` tuple as returned by
#     `sys.exc_info`.
#     """
#     # 2to3 isn't smart enough to convert three-argument raise
#     # statements correctly in some cases.
#     if isinstance(exc_info[1], exc_info[0]):
#         raise exc_info[1], None, exc_info[2]
#         # After 2to3: raise exc_info[1].with_traceback(exc_info[2])
#     else:
#         # I think this branch is only taken for string exceptions,
#         # which were removed in Python 2.6.
#         raise exc_info[0], exc_info[1], exc_info[2]
#         # After 2to3: raise exc_info[0](exc_info[1]).with_traceback(exc_info[2])


import contextlib
import functools
import operator
import sys
import threading
from tornado.util import raise_exc_info

    Copied from the python 2.6 standard library.  It's no longer present
    in python 3 because the with statement natively supports multiple
    context managers, but that doesn't help if the list of context
    managers is not known until runtime.
    """
    exits = []
    vars = []
    exc = (None, None, None)
    try:
        for mgr in managers:
            exit = mgr.__exit__
            enter = mgr.__enter__
            vars.append(enter())
            exits.append(exit)
        yield vars
    except:
        exc = sys.exc_info()
    finally:
        while exits:
            exit = exits.pop()
            try:
                if exit(*exc):
                    exc = (None, None, None)
            except:
                exc = sys.exc_info()
        if exc != (None, None, None):
            # Don't rely on sys.exc_info() still containing
            # the right information. Another exception may
            # have been raised and caught by an exit method

# Path: tornado/util.py
# def raise_exc_info(exc_info):
#     """Re-raise an exception (with original traceback) from an exc_info tuple.
# 
#     The argument is a ``(type, value, traceback)`` tuple as returned by
#     `sys.exc_info`.
#     """
#     # 2to3 isn't smart enough to convert three-argument raise
#     # statements correctly in some cases.
#     if isinstance(exc_info[1], exc_info[0]):
#         raise exc_info[1], None, exc_info[2]
#         # After 2to3: raise exc_info[1].with_traceback(exc_info[2])
#     else:
#         # I think this branch is only taken for string exceptions,
#         # which were removed in Python 2.6.
#         raise exc_info[0], exc_info[1], exc_info[2]
#         # After 2to3: raise exc_info[0](exc_info[1]).with_traceback(exc_info[2])


# Path: tornado/stack_context.py
import contextlib
import functools
import operator
import sys
import threading
from tornado.util import raise_exc_info


    Copied from the python 2.6 standard library.  It's no longer present
    in python 3 because the with statement natively supports multiple
    context managers, but that doesn't help if the list of context
    managers is not known until runtime.
    """
    exits = []
    vars = []
    exc = (None, None, None)
    try:
        for mgr in managers:
            exit = mgr.__exit__
            enter = mgr.__enter__
            vars.append(enter())
            exits.append(exit)
        yield vars
    except:
        exc = sys.exc_info()
    finally:
        while exits:
            exit = exits.pop()
            try:
                if exit(*exc):
                    exc = (None, None, None)
            except:
                exc = sys.exc_info()
        if exc != (None, None, None):
            # Don't rely on sys.exc_info() still containing
            # the right information. Another exception may
            # have been raised and caught by an exit method

            raise_exc_info(exc)