# HG changeset patch # User jruigrok # Date 1197546696 0 # Node ID 03b4ed33d4136e807a1e418b8c0884e4fc573e28 # Parent 24418e7f9ee54a23a5f7aa0adbed8b5efd0cbcc0 When using sys.stdout with a pipe or redirection the sys.stdout.encoding value will be set to None instead of what the environment first specified through any locale setting. As such, fall back to locale.getpreferredencoding() before the ultimate fallback to ASCII. OK: cmlenz closes: #76 diff --git a/babel/messages/frontend.py b/babel/messages/frontend.py --- a/babel/messages/frontend.py +++ b/babel/messages/frontend.py @@ -19,6 +19,7 @@ from distutils import log from distutils.cmd import Command from distutils.errors import DistutilsOptionError, DistutilsSetupError +from locale import getpreferredencoding import logging from optparse import OptionParser import os @@ -632,7 +633,9 @@ for identifier in localedata.list(): locale = Locale.parse(identifier) output = format % (identifier, locale.english_name) - print output.encode(sys.stdout.encoding or 'ascii', 'replace') + print output.encode(sys.stdout.encoding or + getpreferredencoding() or + 'ascii', 'replace') return 0 if not args: