|
1 | 1 | # -*- coding:utf-8 -*- |
2 | 2 |
|
| 3 | +import six |
3 | 4 | import sys |
4 | 5 | import time |
5 | 6 | import logging |
@@ -38,28 +39,21 @@ def __init__(self, color, *args, **kwargs): |
38 | 39 | logging.Formatter.__init__(self, *args, **kwargs) |
39 | 40 | self._color = color |
40 | 41 | if color: |
41 | | - # The curses module has some str/bytes confusion in |
42 | | - # python3. Until version 3.2.3, most methods return |
43 | | - # bytes, but only accept strings. In addition, we want to |
44 | | - # output these strings with the logging module, which |
45 | | - # works with unicode strings. The explicit calls to |
46 | | - # unicode() below are harmless in python2 but will do the |
47 | | - # right conversion in python 3. |
48 | 42 | fg_color = (curses.tigetstr("setaf") or |
49 | 43 | curses.tigetstr("setf") or "") |
50 | 44 | if (3, 0) < sys.version_info < (3, 2, 3): |
51 | | - fg_color = unicode(fg_color, "ascii") |
| 45 | + fg_color = six.text_type(fg_color, "ascii") |
52 | 46 | self._colors = { |
53 | | - logging.DEBUG: unicode(curses.tparm(fg_color, 4), |
| 47 | + logging.DEBUG: six.text_type(curses.tparm(fg_color, 4), |
54 | 48 | "ascii"), # Blue |
55 | | - logging.INFO: unicode(curses.tparm(fg_color, 2), |
| 49 | + logging.INFO: six.text_type(curses.tparm(fg_color, 2), |
56 | 50 | "ascii"), # Green |
57 | | - logging.WARNING: unicode(curses.tparm(fg_color, 3), |
| 51 | + logging.WARNING: six.text_type(curses.tparm(fg_color, 3), |
58 | 52 | "ascii"), # Yellow |
59 | | - logging.ERROR: unicode(curses.tparm(fg_color, 1), |
| 53 | + logging.ERROR: six.text_type(curses.tparm(fg_color, 1), |
60 | 54 | "ascii"), # Red |
61 | 55 | } |
62 | | - self._normal = unicode(curses.tigetstr("sgr0"), "ascii") |
| 56 | + self._normal = six.text_type(curses.tigetstr("sgr0"), "ascii") |
63 | 57 |
|
64 | 58 | def format(self, record): |
65 | 59 | try: |
|
0 commit comments