← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:py3-poparser-unescape into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:py3-poparser-unescape into launchpad:master.

Commit message:
Port POParser._unescapeNumericCharSequence to Python 3

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/398527

The string_escape codec no longer exists, so we need a slightly different approach.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-poparser-unescape into launchpad:master.
diff --git a/lib/lp/translations/utilities/gettext_po_parser.py b/lib/lp/translations/utilities/gettext_po_parser.py
index d814bf3..925af2d 100644
--- a/lib/lp/translations/utilities/gettext_po_parser.py
+++ b/lib/lp/translations/utilities/gettext_po_parser.py
@@ -691,7 +691,12 @@ class POParser(object):
         # We found some text escaped that should be recoded to Unicode.
         # First, we unescape it.
         escaped_string, string = string[:position], string[position:]
-        unescaped_string = escaped_string.decode('string-escape')
+        # Effectively a bytes-to-bytes string-escape decoding, but
+        # compatible with Python 3.  This works because we've already
+        # ensured above that escaped_string only includes hexadecimal or
+        # octal escapes (not \uXXXX etc.).
+        unescaped_string = escaped_string.encode('ascii').decode(
+            'unicode-escape').encode('iso-8859-1')
 
         if (self._translation_file is not None and
             self._translation_file.header is not None):