ソースを参照

Handle unprintable characters when printing to stdout and stderr.

Jonas Borgström 14 年 前
コミット
4f86304437
1 ファイル変更4 行追加0 行削除
  1. 4 0
      darc/archiver.py

+ 4 - 0
darc/archiver.py

@@ -22,12 +22,16 @@ class Archiver(object):
 
     def print_error(self, msg, *args):
         msg = args and msg % args or msg
+        if hasattr(sys.stderr, 'encoding'):
+            msg = msg.encode(sys.stderr.encoding, 'ignore')
         self.exit_code = 1
         print >> sys.stderr, msg
 
     def print_verbose(self, msg, *args, **kw):
         if self.verbose:
             msg = args and msg % args or msg
+            if hasattr(sys.stdout, 'encoding'):
+                msg = msg.encode(sys.stdout.encoding, 'ignore')
             if kw.get('newline', True):
                 print msg
             else: