From: Morgan Wahl Date: Sat, 26 Feb 2022 00:08:12 +0000 (-0500) Subject: Fix output of --list-locales to not be a bytes repr X-Git-Tag: v2.10.0~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8ef344d9bfabee9bb92d1a87da1f238feef2a380;p=thirdparty%2Fbabel.git Fix output of --list-locales to not be a bytes repr Co-authored-by: Aarni Koskela --- diff --git a/babel/messages/frontend.py b/babel/messages/frontend.py index c71bc0d7..36f80f1c 100644 --- a/babel/messages/frontend.py +++ b/babel/messages/frontend.py @@ -22,7 +22,6 @@ from collections import OrderedDict from configparser import RawConfigParser from datetime import datetime from io import StringIO -from locale import getpreferredencoding from babel import __version__ as VERSION from babel import Locale, localedata @@ -906,10 +905,7 @@ class CommandLineInterface(object): format = u'%%-%ds %%s' % (longest + 1) for identifier in identifiers: locale = Locale.parse(identifier) - output = format % (identifier, locale.english_name) - print(output.encode(sys.stdout.encoding or - getpreferredencoding() or - 'ascii', 'replace')) + print(format % (identifier, locale.english_name)) return 0 if not args: diff --git a/tests/messages/test_frontend.py b/tests/messages/test_frontend.py index f8a58dd2..40afab7f 100644 --- a/tests/messages/test_frontend.py +++ b/tests/messages/test_frontend.py @@ -756,6 +756,17 @@ usage: pybabel command [options] [args] pybabel: error: no valid command or option passed. try the -h/--help option for more information. """, sys.stderr.getvalue().lower()) + def test_list_locales(self): + """ + Test the command with the --list-locales arg. + """ + result = self.cli.run(sys.argv + ['--list-locales']) + assert not result + output = sys.stdout.getvalue() + assert 'fr_CH' in output + assert 'French (Switzerland)' in output + assert "\nb'" not in output # No bytes repr markers in output + def _run_init_catalog(self): i18n_dir = os.path.join(data_dir, 'project', 'i18n') pot_path = os.path.join(data_dir, 'project', 'i18n', 'messages.pot')