]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Cherry-pick b151a1ee967 into branch2.2.
authorBen Darnell <ben@bendarnell.com>
Tue, 31 Jan 2012 08:34:12 +0000 (00:34 -0800)
committerBen Darnell <ben@bendarnell.com>
Tue, 24 Apr 2012 04:37:34 +0000 (21:37 -0700)
Original commit message:

Add a version check for the curses unicode hack so it won't break when
python 3.2.3 or 3.3 are released.

Closes #450.

tornado/options.py

index f9f472fff77d41bce8a66763334578eece0c76a4..5fb91e1fe1a32320ebcaa3cc04105463aae018d5 100644 (file)
@@ -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"),