← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:py3-decode-not-unicode into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:py3-decode-not-unicode into launchpad:master.

Commit message:
Use bytes.decode() rather than unicode(bytes)

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

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

This is clearer and more Python-3-friendly.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-decode-not-unicode into launchpad:master.
diff --git a/lib/lp/services/webapp/servers.py b/lib/lp/services/webapp/servers.py
index ab9764b..e23198e 100644
--- a/lib/lp/services/webapp/servers.py
+++ b/lib/lp/services/webapp/servers.py
@@ -665,11 +665,11 @@ class LaunchpadBrowserRequest(BasicLaunchpadRequest, BrowserRequest,
 
     def _decode(self, text):
         text = super(LaunchpadBrowserRequest, self)._decode(text)
-        if isinstance(text, str):
+        if isinstance(text, bytes):
             # BrowserRequest._decode failed to do so with the user-specified
             # charsets, so decode as UTF-8 with replacements, since we always
             # want unicode.
-            text = unicode(text, 'utf-8', 'replace')
+            text = text.decode('utf-8', 'replace')
         return text
 
     @cachedproperty
diff --git a/lib/lp/translations/utilities/gettext_po_parser.py b/lib/lp/translations/utilities/gettext_po_parser.py
index c11de08..865d0c5 100644
--- a/lib/lp/translations/utilities/gettext_po_parser.py
+++ b/lib/lp/translations/utilities/gettext_po_parser.py
@@ -190,11 +190,11 @@ class POHeader:
             return text
         charset = self.charset
         try:
-            text = unicode(text, charset)
+            text = text.decode(charset)
         except UnicodeError:
             self._emitSyntaxWarning(
                 'String is not in declared charset %r' % charset)
-            text = unicode(text, charset, 'replace')
+            text = text.decode(charset, 'replace')
         except LookupError:
             raise TranslationFormatInvalidInputError(
                 message='Unknown charset %r' % charset)