Skip to content

Commit 2cd7ea5

Browse files
Commit
1 parent c7f1da9 commit 2cd7ea5

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

Lib/test/test_tools/test_i18n.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,17 @@ def test_multiple_keywords_same_funcname_errors(self):
591591
'\tkeyword="_": Expected a string constant for argument 1, got 42\n'
592592
'\tkeyword="_:2": Expected a string constant for argument 2, got y\n')
593593

594+
def test_utf8_encoding(self):
595+
with temp_cwd(None):
596+
with open('test.py', 'w', encoding='utf-8') as fp:
597+
fp.write('_("áscii")')
598+
599+
res = assert_python_ok(self.script, 'test.py', PYTHONCOERCECLOCALE="0", PYTHONUTF8="0", PYTHONIOENCODING="ascii", LANG="C", LC_ALL="C")
600+
self.assertEqual(res.err, b'')
601+
602+
with open('messages.pot', encoding='utf-8') as fp:
603+
pot_content = fp.read()
604+
self.assertIn('áscii', pot_content)
594605

595606
def extract_from_snapshots():
596607
snapshots = {

Tools/i18n/pygettext.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ class Options:
767767
elif opt in ('-x', '--exclude-file'):
768768
options.excludefilename = arg
769769
elif opt in ('-X', '--no-docstrings'):
770-
fp = open(arg)
770+
fp = open(arg, encoding='utf-8')
771771
try:
772772
while 1:
773773
line = fp.readline()
@@ -794,7 +794,7 @@ class Options:
794794
# initialize list of strings to exclude
795795
if options.excludefilename:
796796
try:
797-
with open(options.excludefilename) as fp:
797+
with open(options.excludefilename, encoding='utf-8') as fp:
798798
options.toexclude = fp.readlines()
799799
except OSError:
800800
print(f"Can't read --exclude-file: {options.excludefilename}",
@@ -834,7 +834,7 @@ class Options:
834834
else:
835835
if options.outpath:
836836
options.outfile = os.path.join(options.outpath, options.outfile)
837-
fp = open(options.outfile, 'w')
837+
fp = open(options.outfile, 'w', encoding='utf-8')
838838
closep = 1
839839
try:
840840
write_pot_file(visitor.messages, options, fp)

0 commit comments

Comments
 (0)