# 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])
# 
# class Configurable(object):
#     """Base class for configurable interfaces.
# 
#     A configurable interface is an (abstract) class whose constructor
#     acts as a factory function for one of its implementation subclasses.
#     The implementation subclass as well as optional keyword arguments to
#     its initializer can be set globally at runtime with `configure`.
# 
#     By using the constructor as the factory method, the interface looks like
#     a normal class, ``isinstance()`` works as usual, etc.  This pattern
#     is most useful when the choice of implementation is likely to be a
#     global decision (e.g. when epoll is available, always use it instead of
#     select), or when a previously-monolithic class has been split into
#     specialized subclasses.
# 
#     Configurable subclasses must define the class methods
#     `configurable_base` and `configurable_default`, and use the instance
#     method `initialize` instead of `__init__`.
#     """
#     __impl_class = None
#     __impl_kwargs = None
# 
#     def __new__(cls, **kwargs):
#         base = cls.configurable_base()
#         args = {}
#         if cls is base:
#             impl = cls.configured_class()
#             if base.__impl_kwargs:
#                 args.update(base.__impl_kwargs)
#         else:
#             impl = cls
#         args.update(kwargs)
#         instance = super(Configurable, cls).__new__(impl)
#         # initialize vs __init__ chosen for compatiblity with AsyncHTTPClient
#         # singleton magic.  If we get rid of that we can switch to __init__
#         # here too.
#         instance.initialize(**args)
#         return instance
# 
#     @classmethod
#     def configurable_base(cls):
#         """Returns the base class of a configurable hierarchy.
# 
#         This will normally return the class in which it is defined.
#         (which is *not* necessarily the same as the cls classmethod parameter).
#         """
#         raise NotImplementedError()
# 
#     @classmethod
#     def configurable_default(cls):
#         """Returns the implementation class to be used if none is configured."""
#         raise NotImplementedError()
# 
#     def initialize(self):
#         """Initialize a `Configurable` subclass instance.
# 
#         Configurable classes should use `initialize` instead of `__init__`.
#         """
# 
#     @classmethod
#     def configure(cls, impl, **kwargs):
#         """Sets the class to use when the base class is instantiated.
# 
#         Keyword arguments will be saved and added to the arguments passed
#         to the constructor.  This can be used to set global defaults for
#         some parameters.
#         """
#         base = cls.configurable_base()
#         if isinstance(impl, (unicode, bytes_type)):
#             impl = import_object(impl)
#         if impl is not None and not issubclass(impl, cls):
#             raise ValueError("Invalid subclass of %s" % cls)
#         base.__impl_class = impl
#         base.__impl_kwargs = kwargs
# 
#     @classmethod
#     def configured_class(cls):
#         """Returns the currently configured class."""
#         base = cls.configurable_base()
#         if cls.__impl_class is None:
#             base.__impl_class = cls.configurable_default()
#         return base.__impl_class
# 
# 
#     @classmethod
#     def _save_configuration(cls):
#         base = cls.configurable_base()
#         return (base.__impl_class, base.__impl_kwargs)
# 
#     @classmethod
#     def _restore_configuration(cls, saved):
#         base = cls.configurable_base()
#         base.__impl_class = saved[0]
#         base.__impl_kwargs = saved[1]
# 
# Path: tornado/test/util.py



import sys
from tornado.util import raise_exc_info, Configurable
from tornado.test.util import unittest
                super(TwoArgException, self).__init__()
                self.a, self.b = a, b

        try:
            raise TwoArgException(1, 2)
        except TwoArgException:
            exc_info = sys.exc_info()
        try:
            raise_exc_info(exc_info)
            self.fail("didn't get expected exception")
        except TwoArgException, e:
            self.assertIs(e, exc_info[1])

class TestConfigurable(Configurable):
    @classmethod
    def configurable_base(cls):
        return TestConfigurable

    @classmethod
    def configurable_default(cls):
        return TestConfig1

class TestConfig1(TestConfigurable):
    def initialize(self, a=None):
        self.a = a

class TestConfig2(TestConfigurable):
    def initialize(self, b=None):
        self.b = b


# 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])
# 
# class Configurable(object):
#     """Base class for configurable interfaces.
# 
#     A configurable interface is an (abstract) class whose constructor
#     acts as a factory function for one of its implementation subclasses.
#     The implementation subclass as well as optional keyword arguments to
#     its initializer can be set globally at runtime with `configure`.
# 
#     By using the constructor as the factory method, the interface looks like
#     a normal class, ``isinstance()`` works as usual, etc.  This pattern
#     is most useful when the choice of implementation is likely to be a
#     global decision (e.g. when epoll is available, always use it instead of
#     select), or when a previously-monolithic class has been split into
#     specialized subclasses.
# 
#     Configurable subclasses must define the class methods
#     `configurable_base` and `configurable_default`, and use the instance
#     method `initialize` instead of `__init__`.
#     """
#     __impl_class = None
#     __impl_kwargs = None
# 
#     def __new__(cls, **kwargs):
#         base = cls.configurable_base()
#         args = {}
#         if cls is base:
#             impl = cls.configured_class()
#             if base.__impl_kwargs:
#                 args.update(base.__impl_kwargs)
#         else:
#             impl = cls
#         args.update(kwargs)
#         instance = super(Configurable, cls).__new__(impl)
#         # initialize vs __init__ chosen for compatiblity with AsyncHTTPClient
#         # singleton magic.  If we get rid of that we can switch to __init__
#         # here too.
#         instance.initialize(**args)
#         return instance
# 
#     @classmethod
#     def configurable_base(cls):
#         """Returns the base class of a configurable hierarchy.
# 
#         This will normally return the class in which it is defined.
#         (which is *not* necessarily the same as the cls classmethod parameter).
#         """
#         raise NotImplementedError()
# 
#     @classmethod
#     def configurable_default(cls):
#         """Returns the implementation class to be used if none is configured."""
#         raise NotImplementedError()
# 
#     def initialize(self):
#         """Initialize a `Configurable` subclass instance.
# 
#         Configurable classes should use `initialize` instead of `__init__`.
#         """
# 
#     @classmethod
#     def configure(cls, impl, **kwargs):
#         """Sets the class to use when the base class is instantiated.
# 
#         Keyword arguments will be saved and added to the arguments passed
#         to the constructor.  This can be used to set global defaults for
#         some parameters.
#         """
#         base = cls.configurable_base()
#         if isinstance(impl, (unicode, bytes_type)):
#             impl = import_object(impl)
#         if impl is not None and not issubclass(impl, cls):
#             raise ValueError("Invalid subclass of %s" % cls)
#         base.__impl_class = impl
#         base.__impl_kwargs = kwargs
# 
#     @classmethod
#     def configured_class(cls):
#         """Returns the currently configured class."""
#         base = cls.configurable_base()
#         if cls.__impl_class is None:
#             base.__impl_class = cls.configurable_default()
#         return base.__impl_class
# 
# 
#     @classmethod
#     def _save_configuration(cls):
#         base = cls.configurable_base()
#         return (base.__impl_class, base.__impl_kwargs)
# 
#     @classmethod
#     def _restore_configuration(cls, saved):
#         base = cls.configurable_base()
#         base.__impl_class = saved[0]
#         base.__impl_kwargs = saved[1]
# 
# Path: tornado/test/util.py



# Path: tornado/test/util_test.py
import sys
from tornado.util import raise_exc_info, Configurable
from tornado.test.util import unittest

                super(TwoArgException, self).__init__()
                self.a, self.b = a, b

        try:
            raise TwoArgException(1, 2)
        except TwoArgException:
            exc_info = sys.exc_info()
        try:
            raise_exc_info(exc_info)
            self.fail("didn't get expected exception")
        except TwoArgException, e:
            self.assertIs(e, exc_info[1])

class TestConfigurable(Configurable):
    @classmethod
    def configurable_base(cls):
        return TestConfigurable

    @classmethod
    def configurable_default(cls):
        return TestConfig1

class TestConfig1(TestConfigurable):
    def initialize(self, a=None):
        self.a = a

class TestConfig2(TestConfigurable):
    def initialize(self, b=None):
        self.b = b


class ConfigurableTest(unittest.TestCase):