# Path: torext/utils.py
# def split_kwargs(kwgs_tuple, kwgs):
#     _kwgs = {}
#     for i in kwgs_tuple:
#         if i in kwgs:
#             _kwgs[i] = kwgs.pop(i)
#     return _kwgs
# 
# Path: torext/compat.py
# def unicode_(s, *args):
#     return unicode(s, *args)
# 
# def decode_(s, *args):
#     return s.decode(*args)


import sys
import logging
        import curses
from torext.utils import split_kwargs
from torext.compat import unicode_ as u_, decode_
    from nose.plugins.logcapture import MyMemoryHandler
request_log = logging.getLogger('torext.request')


# borrow from tornado.options._LogFormatter.__init__
def _color(lvl):
    try:
    except ImportError:
        curses = None
    color = False
    if curses and sys.stderr.isatty():
        try:
            curses.setupterm()
            if curses.tigetnum("colors") > 0:
                color = True
        except:
            pass
    if not color:
        return u_(''), u_('')
    # The curses module has some str/bytes confusion in
    # python3.  Until version 3.2.3, most methods return
    # bytes, but only accept strings.  In addition, we want to
    # output these strings with the logging module, which
    # works with unicode strings.  The explicit calls to
    # unicode() below are harmless in python2 but will do the
    # right conversion in python 3.
    fg_color = (curses.tigetstr("setaf") or
                curses.tigetstr("setf") or "")
    if (3, 0) < sys.version_info < (3, 2, 3):
        fg_color = u_(fg_color, "ascii")
    colors_map = {

# Path: torext/utils.py
# def split_kwargs(kwgs_tuple, kwgs):
#     _kwgs = {}
#     for i in kwgs_tuple:
#         if i in kwgs:
#             _kwgs[i] = kwgs.pop(i)
#     return _kwgs
# 
# Path: torext/compat.py
# def unicode_(s, *args):
#     return unicode(s, *args)
# 
# def decode_(s, *args):
#     return s.decode(*args)


# Path: torext/log.py
import sys
import logging
        import curses
from torext.utils import split_kwargs
from torext.compat import unicode_ as u_, decode_
    from nose.plugins.logcapture import MyMemoryHandler

request_log = logging.getLogger('torext.request')


# borrow from tornado.options._LogFormatter.__init__
def _color(lvl):
    try:
    except ImportError:
        curses = None
    color = False
    if curses and sys.stderr.isatty():
        try:
            curses.setupterm()
            if curses.tigetnum("colors") > 0:
                color = True
        except:
            pass
    if not color:
        return u_(''), u_('')
    # The curses module has some str/bytes confusion in
    # python3.  Until version 3.2.3, most methods return
    # bytes, but only accept strings.  In addition, we want to
    # output these strings with the logging module, which
    # works with unicode strings.  The explicit calls to
    # unicode() below are harmless in python2 but will do the
    # right conversion in python 3.
    fg_color = (curses.tigetstr("setaf") or
                curses.tigetstr("setf") or "")
    if (3, 0) < sys.version_info < (3, 2, 3):
        fg_color = u_(fg_color, "ascii")
    colors_map = {

        logging.DEBUG: u_(curses.tparm(fg_color, 4),  # Blue