Skip to content

Commit 15798a1

Browse files
committed
Cherry-pick b151a1e into branch2.2.
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 tornadoweb#450.
1 parent c1f72d5 commit 15798a1

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

tornado/options.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,12 +354,17 @@ def __init__(self, color, *args, **kwargs):
354354
logging.Formatter.__init__(self, *args, **kwargs)
355355
self._color = color
356356
if color:
357-
# The curses module has some str/bytes confusion in python3.
358-
# Most methods return bytes, but only accept strings.
359-
# The explict calls to unicode() below are harmless in python2,
360-
# but will do the right conversion in python3.
361-
fg_color = unicode(curses.tigetstr("setaf") or
362-
curses.tigetstr("setf") or "", "ascii")
357+
# The curses module has some str/bytes confusion in
358+
# python3. Until version 3.2.3, most methods return
359+
# bytes, but only accept strings. In addition, we want to
360+
# output these strings with the logging module, which
361+
# works with unicode strings. The explicit calls to
362+
# unicode() below are harmless in python2 but will do the
363+
# right conversion in python 3.
364+
fg_color = (curses.tigetstr("setaf") or
365+
curses.tigetstr("setf") or "")
366+
if (3, 0) < sys.version_info < (3, 2, 3):
367+
fg_color = unicode(fg_color, "ascii")
363368
self._colors = {
364369
logging.DEBUG: unicode(curses.tparm(fg_color, 4), # Blue
365370
"ascii"),

0 commit comments

Comments
 (0)