Browse Source

term.colored broke on non-ascii data. Closes #427. Thanks to kmike

Ask Solem 13 years ago
parent
commit
dde8868182
1 changed files with 8 additions and 5 deletions
  1. 8 5
      celery/utils/term.py

+ 8 - 5
celery/utils/term.py

@@ -11,6 +11,8 @@ term utils.
 """
 import platform
 
+from celery.utils.encoding import safe_str
+
 BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = range(8)
 OP_SEQ = "\033[%dm"
 RESET_SEQ = "\033[0m"
@@ -21,6 +23,7 @@ SYSTEM = platform.system()
 IS_WINDOWS = SYSTEM == "Windows"
 
 
+
 class colored(object):
 
     def __init__(self, *s, **kwargs):
@@ -39,17 +42,17 @@ class colored(object):
                       "white": self.white}
 
     def _add(self, a, b):
-        return str(a) + str(b)
+        return safe_str(a) + safe_str(b)
 
     def _fold_no_color(self, a, b):
         try:
             A = a.no_color()
         except AttributeError:
-            A = str(a)
+            A = safe_str(a)
         try:
             B = b.no_color()
         except AttributeError:
-            B = str(b)
+            B = safe_str(b)
         return A + B
 
     def no_color(self):
@@ -59,7 +62,7 @@ class colored(object):
         prefix = ""
         if self.enabled:
             prefix = self.op
-        return prefix + str(reduce(self._add, self.s))
+        return prefix + safe_str(reduce(self._add, self.s))
 
     def __str__(self):
         suffix = ""
@@ -137,4 +140,4 @@ class colored(object):
         return self.node(s or [""], RESET_SEQ)
 
     def __add__(self, other):
-        return str(self) + str(other)
+        return safe_str(self) + safe_str(other)