From: Ben Darnell Date: Thu, 24 Feb 2011 00:53:32 +0000 (-0800) Subject: Fix encoding issues in options.py for python3. X-Git-Tag: v2.0.0~121 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a72cc17f7261bab16c8820410616b46c3138b7c7;p=thirdparty%2Ftornado.git Fix encoding issues in options.py for python3. --- diff --git a/tornado/options.py b/tornado/options.py index 5b09628b8..35c695783 100644 --- a/tornado/options.py +++ b/tornado/options.py @@ -335,14 +335,23 @@ class _LogFormatter(logging.Formatter): logging.Formatter.__init__(self, *args, **kwargs) self._color = color if color: - fg_color = curses.tigetstr("setaf") or curses.tigetstr("setf") or "" + # 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") self._colors = { - logging.DEBUG: curses.tparm(fg_color, 4), # Blue - logging.INFO: curses.tparm(fg_color, 2), # Green - logging.WARNING: curses.tparm(fg_color, 3), # Yellow - logging.ERROR: curses.tparm(fg_color, 1), # Red + logging.DEBUG: unicode(curses.tparm(fg_color, 4), # Blue + "ascii"), + logging.INFO: unicode(curses.tparm(fg_color, 2), # Green + "ascii"), + logging.WARNING: unicode(curses.tparm(fg_color, 3), # Yellow + "ascii"), + logging.ERROR: unicode(curses.tparm(fg_color, 1), # Red + "ascii"), } - self._normal = curses.tigetstr("sgr0") + self._normal = unicode(curses.tigetstr("sgr0"), "ascii") def format(self, record): try: