← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:py3-pageid-str into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:py3-pageid-str into launchpad:master.

Commit message:
Make constructPageID return a native string

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

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

On Python 3, we want str rather than bytes.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-pageid-str into launchpad:master.
diff --git a/lib/lp/services/webapp/publication.py b/lib/lp/services/webapp/publication.py
index 6324a64..86a8b65 100644
--- a/lib/lp/services/webapp/publication.py
+++ b/lib/lp/services/webapp/publication.py
@@ -410,10 +410,10 @@ class LaunchpadBrowserPublication(
                 return self.constructPageID(context, context.context, names)
             view_names = ':'.join(names)
             pageid = '%s:%s' % (context_name, view_names)
-        # The view name used in the pageid usually comes from ZCML and so
-        # it will be a unicode string although it shouldn't.  To avoid
-        # problems we encode it into ASCII.
-        return pageid.encode('US-ASCII')
+        # The view name used in the pageid usually comes from ZCML and so it
+        # will be a Unicode string, but we want a native string.  On Python
+        # 2, to avoid problems we encode it into ASCII.
+        return six.ensure_str(pageid, 'US-ASCII')
 
     def callObject(self, request, ob):
         """See `zope.publisher.interfaces.IPublication`.