]> granicus.if.org Git - python/commitdiff
Issue #17156: pygettext.py now correctly escapes non-ascii characters.
authorSerhiy Storchaka <storchaka@gmail.com>
Sat, 9 Feb 2013 20:36:22 +0000 (22:36 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Sat, 9 Feb 2013 20:36:22 +0000 (22:36 +0200)
Misc/NEWS
Tools/i18n/pygettext.py

index 71db196a5e9cbcea97662b4cb2e12801881e9d8d..b63d04c35da4a6d485eb85ffb9d15351af75d57d 100644 (file)
--- 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.
 
index bb0dd35da9b04b2e6ab728767fb846f5d884b89b..38a88822d9b61a81db273ab6d8d9c5f8498245ba 100755 (executable)
@@ -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)