From 4f86304437b9d95f52b9a2b13624f70da17d07c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Borgstr=C3=B6m?= Date: Thu, 4 Nov 2010 21:21:04 +0100 Subject: [PATCH] Handle unprintable characters when printing to stdout and stderr. --- darc/archiver.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/darc/archiver.py b/darc/archiver.py index 5e1f0d6eb..38fa870fd 100644 --- a/darc/archiver.py +++ b/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: