summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-02-09 22:36:22 +0200
committerSerhiy Storchaka <storchaka@gmail.com>2013-02-09 22:36:22 +0200
commit15ea3ac67ae600ad75f2230b68e86a70da864942 (patch)
treee69ca1fe5578223388d2a3e3c9173f500ae5cc20
parent4234992c750cad2bbf36f712a47515f050df549f (diff)
downloadcpython-git-15ea3ac67ae600ad75f2230b68e86a70da864942.tar.gz
Issue #17156: pygettext.py now correctly escapes non-ascii characters.
-rw-r--r--Misc/NEWS2
-rwxr-xr-xTools/i18n/pygettext.py11
2 files changed, 7 insertions, 6 deletions
diff --git a/Misc/NEWS b/Misc/NEWS
index 71db196a5e..b63d04c35d 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -202,6 +202,8 @@ Core and Builtins
Library
-------
+- Issue #17156: pygettext.py now correctly escapes non-ascii characters.
+
- Issue #7358: cStringIO.StringIO now supports writing to and reading from
a stream larger than 2 GiB on 64-bit systems.
diff --git a/Tools/i18n/pygettext.py b/Tools/i18n/pygettext.py
index bb0dd35da9..38a88822d9 100755
--- a/Tools/i18n/pygettext.py
+++ b/Tools/i18n/pygettext.py
@@ -208,6 +208,7 @@ escapes = []
def make_escapes(pass_iso8859):
global escapes
+ escapes = [chr(i) for i in range(256)]
if pass_iso8859:
# Allow iso-8859 characters to pass through so that e.g. 'msgid
# "Höhe"' would result not result in 'msgid "H\366he"'. Otherwise we
@@ -215,11 +216,9 @@ def make_escapes(pass_iso8859):
mod = 128
else:
mod = 256
- for i in range(256):
- if 32 <= (i % mod) <= 126:
- escapes.append(chr(i))
- else:
- escapes.append("\\%03o" % i)
+ for i in range(mod):
+ if not(32 <= i <= 126):
+ escapes[i] = "\\%03o" % i
escapes[ord('\\')] = '\\\\'
escapes[ord('\t')] = '\\t'
escapes[ord('\r')] = '\\r'
@@ -593,7 +592,7 @@ def main():
fp.close()
# calculate escapes
- make_escapes(options.escape)
+ make_escapes(not options.escape)
# calculate all keywords
options.keywords.extend(default_keywords)