# Path: tornado/log.py
# def _stderr_supports_color():
#     def __init__(self, color=True, *args, **kwargs):
#     def format(self, record):
# def enable_pretty_logging(options=None):
# def define_logging_options(options=None):
# class LogFormatter(logging.Formatter):
# 
# Path: tornado/stack_context.py
# class ExceptionStackContext(object):
#     '''Specialization of StackContext for exception handling.
# 
#     The supplied exception_handler function will be called in the
#     event of an uncaught exception in this context.  The semantics are
#     similar to a try/finally clause, and intended use cases are to log
#     an error, close a socket, or similar cleanup actions.  The
#     exc_info triple (type, value, traceback) will be passed to the
#     exception_handler function.
# 
#     If the exception handler returns true, the exception will be
#     consumed and will not be propagated to other exception handlers.
#     '''
#     def __init__(self, exception_handler, _active_cell=None):
#         self.exception_handler = exception_handler
#         self.active_cell = _active_cell or [True]
# 
#     def __enter__(self):
#         self.old_contexts = _state.contexts
#         _state.contexts = (self.old_contexts +
#                            ((ExceptionStackContext, self.exception_handler,
#                              self.active_cell),))
#         return lambda: operator.setitem(self.active_cell, 0, False)
# 
#     def __exit__(self, type, value, traceback):
#         try:
#             if type is not None:
#                 return self.exception_handler(type, value, traceback)
#         finally:
#             _state.contexts = self.old_contexts
#             self.old_contexts = None
# 
# 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])


from cStringIO import StringIO
    from tornado.httpclient import AsyncHTTPClient
    from tornado.httpserver import HTTPServer
    from tornado.simple_httpclient import SimpleAsyncHTTPClient
    from tornado.ioloop import IOLoop
    from tornado import netutil
from tornado.log import gen_log
from tornado.stack_context import ExceptionStackContext
from tornado.util import raise_exc_info
    from tornado.options import define, options, parse_command_line
import logging
import os
import re
import signal
import socket
import sys
import time
    import unittest2 as unittest
    import unittest
class LogTrapTestCase(unittest.TestCase):
    """A test case that captures and discards all logging output
    if the test passes.

    Some libraries can produce a lot of logging output even when
    the test succeeds, so this class can be useful to minimize the noise.
    Simply use it as a base class for your test case.  It is safe to combine
    with AsyncTestCase via multiple inheritance
    ("class MyTestCase(AsyncHTTPTestCase, LogTrapTestCase):")

    This class assumes that only one log handler is configured and that
    it is a StreamHandler.  This is true for both logging.basicConfig
    and the "pretty logging" configured by tornado.options.
    """
    def run(self, result=None):
        logger = logging.getLogger()
        if len(logger.handlers) > 1:
            # Multiple handlers have been defined.  It gets messy to handle
            # this, especially since the handlers may have different
            # formatters.  Just leave the logging alone in this case.
            super(LogTrapTestCase, self).run(result)
            return
        if not logger.handlers:
            logging.basicConfig()
        self.assertEqual(len(logger.handlers), 1)
        handler = logger.handlers[0]
        assert isinstance(handler, logging.StreamHandler)
        old_stream = handler.stream
        try:
            handler.stream = StringIO()

# Path: tornado/log.py
# def _stderr_supports_color():
#     def __init__(self, color=True, *args, **kwargs):
#     def format(self, record):
# def enable_pretty_logging(options=None):
# def define_logging_options(options=None):
# class LogFormatter(logging.Formatter):
# 
# Path: tornado/stack_context.py
# class ExceptionStackContext(object):
#     '''Specialization of StackContext for exception handling.
# 
#     The supplied exception_handler function will be called in the
#     event of an uncaught exception in this context.  The semantics are
#     similar to a try/finally clause, and intended use cases are to log
#     an error, close a socket, or similar cleanup actions.  The
#     exc_info triple (type, value, traceback) will be passed to the
#     exception_handler function.
# 
#     If the exception handler returns true, the exception will be
#     consumed and will not be propagated to other exception handlers.
#     '''
#     def __init__(self, exception_handler, _active_cell=None):
#         self.exception_handler = exception_handler
#         self.active_cell = _active_cell or [True]
# 
#     def __enter__(self):
#         self.old_contexts = _state.contexts
#         _state.contexts = (self.old_contexts +
#                            ((ExceptionStackContext, self.exception_handler,
#                              self.active_cell),))
#         return lambda: operator.setitem(self.active_cell, 0, False)
# 
#     def __exit__(self, type, value, traceback):
#         try:
#             if type is not None:
#                 return self.exception_handler(type, value, traceback)
#         finally:
#             _state.contexts = self.old_contexts
#             self.old_contexts = None
# 
# 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/testing.py
from cStringIO import StringIO
    from tornado.httpclient import AsyncHTTPClient
    from tornado.httpserver import HTTPServer
    from tornado.simple_httpclient import SimpleAsyncHTTPClient
    from tornado.ioloop import IOLoop
    from tornado import netutil
from tornado.log import gen_log
from tornado.stack_context import ExceptionStackContext
from tornado.util import raise_exc_info
    from tornado.options import define, options, parse_command_line
import logging
import os
import re
import signal
import socket
import sys
import time
    import unittest2 as unittest
    import unittest

class LogTrapTestCase(unittest.TestCase):
    """A test case that captures and discards all logging output
    if the test passes.

    Some libraries can produce a lot of logging output even when
    the test succeeds, so this class can be useful to minimize the noise.
    Simply use it as a base class for your test case.  It is safe to combine
    with AsyncTestCase via multiple inheritance
    ("class MyTestCase(AsyncHTTPTestCase, LogTrapTestCase):")

    This class assumes that only one log handler is configured and that
    it is a StreamHandler.  This is true for both logging.basicConfig
    and the "pretty logging" configured by tornado.options.
    """
    def run(self, result=None):
        logger = logging.getLogger()
        if len(logger.handlers) > 1:
            # Multiple handlers have been defined.  It gets messy to handle
            # this, especially since the handlers may have different
            # formatters.  Just leave the logging alone in this case.
            super(LogTrapTestCase, self).run(result)
            return
        if not logger.handlers:
            logging.basicConfig()
        self.assertEqual(len(logger.handlers), 1)
        handler = logger.handlers[0]
        assert isinstance(handler, logging.StreamHandler)
        old_stream = handler.stream
        try:
            handler.stream = StringIO()

            gen_log.info("RUNNING TEST: " + str(self))