Revision d1c9cf66 snf-webproject/synnefo/webproject/manage.py

b/snf-webproject/synnefo/webproject/manage.py
244 244
        # checks if something is tty:
245 245
        # https://bugzilla.redhat.com/show_bug.cgi?id=841152
246 246
        if not subcommand in ['test'] and not 'shell' in subcommand:
247
            sys.stdout = EncodedStdOut(sys.stdout)
247
            sys.stdout = EncodedStream(sys.stdout)
248
            sys.stderr = EncodedStream(sys.stderr)
248 249

  
249 250
        if subcommand == 'help':
250 251
            if len(args) > 2:
......
309 310
        log.warning("SNF_MANAGE_LOGGING_SETUP setting missing.")
310 311

  
311 312

  
312
class EncodedStdOut(object):
313
    def __init__(self, stdout):
313
class EncodedStream(object):
314
    def __init__(self, stream):
314 315
        try:
315
            std_encoding = stdout.encoding
316
            std_encoding = stream.encoding
316 317
        except AttributeError:
317 318
            std_encoding = None
318 319
        self.encoding = std_encoding or locale.getpreferredencoding()
319
        self.original_stdout = stdout
320
        self.original_stream = stream
320 321

  
321 322
    def write(self, string):
322 323
        if isinstance(string, unicode):
323
            string = string.encode(self.encoding)
324
        self.original_stdout.write(string)
324
            string = string.encode(self.encoding, errors="replace")
325
        self.original_stream.write(string)
325 326

  
326 327
    def __getattr__(self, name):
327
        return getattr(self.original_stdout, name)
328
        return getattr(self.original_stream, name)
328 329

  
329 330

  
330 331
def main():

Also available in: Unified diff