소스 검색

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: