فهرست منبع

Fixes unicode in colored output. Closes #522.

kuno 13 سال پیش
والد
کامیت
8933765e86
2فایلهای تغییر یافته به همراه4 افزوده شده و 2 حذف شده
  1. 2 2
      celery/log.py
  2. 2 0
      celery/utils/encoding.py

+ 2 - 2
celery/log.py

@@ -17,7 +17,7 @@ from . import signals
 from .local import Proxy
 from .utils import LOG_LEVELS, isatty
 from .utils.compat import LoggerAdapter, WatchedFileHandler
-from .utils.encoding import safe_str
+from .utils.encoding import safe_str, str_t
 from .utils.patch import ensure_process_aware_logger
 from .utils.term import colored
 
@@ -46,7 +46,7 @@ class ColorFormatter(logging.Formatter):
 
         if self.use_color and color:
             try:
-                record.msg = str(color(safe_str(record.msg)))
+                record.msg = str_t(color(safe_str(record.msg)))
             except Exception, exc:
                 record.msg = "<Unrepresentable %r: %r>" % (
                         type(record.msg), exc)

+ 2 - 0
celery/utils/encoding.py

@@ -39,6 +39,7 @@ if is_py3k:
             return str_to_bytes(s)
         return s
 
+    str_t = str
     bytes_t = bytes
 
 else:
@@ -54,6 +55,7 @@ else:
     def from_utf8(s, *args, **kwargs):  # noqa
         return s.encode("utf-8", *args, **kwargs)
 
+    str_t = unicode
     bytes_t = str
     ensure_bytes = str_to_bytes