diff --git a/tornado/options.py b/tornado/options.py index f9f472ff..5fb91e1f 100644 --- a/tornado/options.py +++ b/tornado/options.py @@ -354,12 +354,17 @@ class _LogFormatter(logging.Formatter): logging.Formatter.__init__(self, *args, **kwargs) self._color = color if color: - # The curses module has some str/bytes confusion in python3. - # Most methods return bytes, but only accept strings. - # The explict calls to unicode() below are harmless in python2, - # but will do the right conversion in python3. - fg_color = unicode(curses.tigetstr("setaf") or - curses.tigetstr("setf") or "", "ascii") + # 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 = unicode(fg_color, "ascii") self._colors = { logging.DEBUG: unicode(curses.tparm(fg_color, 4), # Blue "ascii"),