encode unicode string from system w/ widechar locale
authorJF Ding <jian-feng.ding@intel.com>
Sun, 24 Jun 2012 14:43:15 +0000 (07:43 -0700)
committerJF Ding <jian-feng.ding@intel.com>
Sun, 24 Jun 2012 14:43:15 +0000 (07:43 -0700)
else in this like system, msger will abort with
string encoding/decoding errors.

mic/msger.py

index 8413f64..33f4298 100644 (file)
@@ -71,6 +71,10 @@ def _general_print(head, color, msg = None, stream = None, level = 'normal'):
         # skip
         return
 
+    # encode raw 'unicode' str to utf8 encoded str
+    if msg and isinstance(msg, unicode):
+        msg = msg.encode('utf-8', 'ignore')
+
     errormsg = ''
     if CATCHERR_BUFFILE_FD > 0:
         size = os.lseek(CATCHERR_BUFFILE_FD , 0, os.SEEK_END)