Handle unprintable characters when printing to stdout and stderr.

This commit is contained in:
Jonas Borgström 2010-11-04 21:21:04 +01:00
parent 330315ba0d
commit 4f86304437
1 changed files with 4 additions and 0 deletions

View File

@ -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: