]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Fix encoding issues in options.py for python3.
authorBen Darnell <ben@bendarnell.com>
Thu, 24 Feb 2011 00:53:32 +0000 (16:53 -0800)
committerBen Darnell <ben@bendarnell.com>
Thu, 24 Feb 2011 00:53:32 +0000 (16:53 -0800)
tornado/options.py

index 5b09628b8519c103d45bde933f8038e428c17b43..35c695783c532df1d7305473784f05c4acfc3d90 100644 (file)
@@ -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: