mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
gh-132121: Always escape non-printable characters in pygettext (GH-132122)
This commit is contained in:
parent
7bb1e1a236
commit
a693eaa710
3 changed files with 6 additions and 5 deletions
|
@ -41,7 +41,7 @@ msgstr ""
|
|||
|
||||
#. some characters in the 128-255 range
|
||||
#: escapes.py:20
|
||||
msgid " ÿ"
|
||||
msgid "\302\200 \302\240 ÿ"
|
||||
msgstr ""
|
||||
|
||||
#. some characters >= 256 encoded as 2, 3 and 4 bytes, respectively
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Always escape non-printable Unicode characters in :program:`pygettext`.
|
|
@ -190,12 +190,10 @@ def make_escapes(pass_nonascii):
|
|||
# Allow non-ascii characters to pass through so that e.g. 'msgid
|
||||
# "Höhe"' would not result in 'msgid "H\366he"'. Otherwise we
|
||||
# escape any character outside the 32..126 range.
|
||||
mod = 128
|
||||
escape = escape_ascii
|
||||
else:
|
||||
mod = 256
|
||||
escape = escape_nonascii
|
||||
escapes = [r"\%03o" % i for i in range(mod)]
|
||||
escapes = [r"\%03o" % i for i in range(256)]
|
||||
for i in range(32, 127):
|
||||
escapes[i] = chr(i)
|
||||
escapes[ord('\\')] = r'\\'
|
||||
|
@ -206,7 +204,9 @@ def make_escapes(pass_nonascii):
|
|||
|
||||
|
||||
def escape_ascii(s, encoding):
|
||||
return ''.join(escapes[ord(c)] if ord(c) < 128 else c for c in s)
|
||||
return ''.join(escapes[ord(c)] if ord(c) < 128 else c
|
||||
if c.isprintable() else escape_nonascii(c, encoding)
|
||||
for c in s)
|
||||
|
||||
|
||||
def escape_nonascii(s, encoding):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue