Skip to content

Commit 87d9983

Browse files
authored
pythongh-130197: pygettext: Test the --escape option (pythonGH-131902)
1 parent e7980ba commit 87d9983

File tree

5 files changed

+138
-3
lines changed

5 files changed

+138
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# SOME DESCRIPTIVE TITLE.
2+
# Copyright (C) YEAR ORGANIZATION
3+
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version: PACKAGE VERSION\n"
8+
"POT-Creation-Date: 2000-01-01 00:00+0000\n"
9+
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
10+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
11+
"Language-Team: LANGUAGE <[email protected]>\n"
12+
"MIME-Version: 1.0\n"
13+
"Content-Type: text/plain; charset=UTF-8\n"
14+
"Content-Transfer-Encoding: 8bit\n"
15+
"Generated-By: pygettext.py 1.5\n"
16+
17+
18+
#. Special characters that are always escaped in the POT file
19+
#: escapes.py:5
20+
msgid ""
21+
"\"\t\n"
22+
"\r\\"
23+
msgstr ""
24+
25+
#. All ascii characters 0-31
26+
#: escapes.py:8
27+
msgid ""
28+
"\000\001\002\003\004\005\006\007\010\t\n"
29+
"\013\014\r\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037"
30+
msgstr ""
31+
32+
#. All ascii characters 32-126
33+
#: escapes.py:13
34+
msgid " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
35+
msgstr ""
36+
37+
#. ascii char 127
38+
#: escapes.py:17
39+
msgid "\177"
40+
msgstr ""
41+
42+
#. some characters in the 128-255 range
43+
#: escapes.py:20
44+
msgid "€   ÿ"
45+
msgstr ""
46+
47+
#. some characters >= 256 encoded as 2, 3 and 4 bytes, respectively
48+
#: escapes.py:23
49+
msgid "α ㄱ 𓂀"
50+
msgstr ""
51+
+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# SOME DESCRIPTIVE TITLE.
2+
# Copyright (C) YEAR ORGANIZATION
3+
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version: PACKAGE VERSION\n"
8+
"POT-Creation-Date: 2000-01-01 00:00+0000\n"
9+
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
10+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
11+
"Language-Team: LANGUAGE <[email protected]>\n"
12+
"MIME-Version: 1.0\n"
13+
"Content-Type: text/plain; charset=UTF-8\n"
14+
"Content-Transfer-Encoding: 8bit\n"
15+
"Generated-By: pygettext.py 1.5\n"
16+
17+
18+
#. Special characters that are always escaped in the POT file
19+
#: escapes.py:5
20+
msgid ""
21+
"\"\t\n"
22+
"\r\\"
23+
msgstr ""
24+
25+
#. All ascii characters 0-31
26+
#: escapes.py:8
27+
msgid ""
28+
"\000\001\002\003\004\005\006\007\010\t\n"
29+
"\013\014\r\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037"
30+
msgstr ""
31+
32+
#. All ascii characters 32-126
33+
#: escapes.py:13
34+
msgid " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
35+
msgstr ""
36+
37+
#. ascii char 127
38+
#: escapes.py:17
39+
msgid "\177"
40+
msgstr ""
41+
42+
#. some characters in the 128-255 range
43+
#: escapes.py:20
44+
msgid "\302\200 \302\240 \303\277"
45+
msgstr ""
46+
47+
#. some characters >= 256 encoded as 2, 3 and 4 bytes, respectively
48+
#: escapes.py:23
49+
msgid "\316\261 \343\204\261 \360\223\202\200"
50+
msgstr ""
51+
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import gettext as _
2+
3+
4+
# Special characters that are always escaped in the POT file
5+
_('"\t\n\r\\')
6+
7+
# All ascii characters 0-31
8+
_('\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n'
9+
'\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15'
10+
'\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f')
11+
12+
# All ascii characters 32-126
13+
_(' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ'
14+
'[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~')
15+
16+
# ascii char 127
17+
_('\x7f')
18+
19+
# some characters in the 128-255 range
20+
_('\x80 \xa0 ÿ')
21+
22+
# some characters >= 256 encoded as 2, 3 and 4 bytes, respectively
23+
_('α ㄱ 𓂀')

Lib/test/test_tools/test_i18n.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -526,11 +526,21 @@ def extract_from_snapshots():
526526
'custom_keywords.py': ('--keyword=foo', '--keyword=nfoo:1,2',
527527
'--keyword=pfoo:1c,2',
528528
'--keyword=npfoo:1c,2,3', '--keyword=_:1,2'),
529+
# == Test character escaping
530+
# Escape ascii and unicode:
531+
'escapes.py': ('--escape', '--add-comments='),
532+
# Escape only ascii and let unicode pass through:
533+
('escapes.py', 'ascii-escapes.pot'): ('--add-comments=',),
529534
}
530535

531536
for filename, args in snapshots.items():
532-
input_file = DATA_DIR / filename
533-
output_file = input_file.with_suffix('.pot')
537+
if isinstance(filename, tuple):
538+
filename, output_file = filename
539+
output_file = DATA_DIR / output_file
540+
input_file = DATA_DIR / filename
541+
else:
542+
input_file = DATA_DIR / filename
543+
output_file = input_file.with_suffix('.pot')
534544
contents = input_file.read_bytes()
535545
with temp_cwd(None):
536546
Path(input_file.name).write_bytes(contents)

Tools/i18n/pygettext.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def make_escapes(pass_nonascii):
188188
global escapes, escape
189189
if pass_nonascii:
190190
# Allow non-ascii characters to pass through so that e.g. 'msgid
191-
# "Höhe"' would result not result in 'msgid "H\366he"'. Otherwise we
191+
# "Höhe"' would not result in 'msgid "H\366he"'. Otherwise we
192192
# escape any character outside the 32..126 range.
193193
mod = 128
194194
escape = escape_ascii

0 commit comments

Comments
 (0)