← Back to team overview

launchpad-reviewers team mailing list archive

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

 

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

Commit message:
Port unicode() calls in lp.registry to Python 3

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

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

This unfortunately requires some contextual clues, because `six.text_type(b'foo')` returns `u'foo'` on Python 2 but `"b'foo'"` on Python 3, while `six.ensure_text` works on bytes or text but not on other types.  Use single-argument `six.text_type` in cases where we know that the argument is not bytes, and `six.ensure_text` where we know the argument is either bytes or text.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-registry-unicode into launchpad:master.
diff --git a/lib/lp/registry/browser/tests/test_distroseries.py b/lib/lp/registry/browser/tests/test_distroseries.py
index 6f710df..0e3e7b4 100644
--- a/lib/lp/registry/browser/tests/test_distroseries.py
+++ b/lib/lp/registry/browser/tests/test_distroseries.py
@@ -1205,8 +1205,8 @@ class TestDistroSeriesLocalDifferences(TestCaseWithFactory,
         rows = diff_table.tbody.findAll('tr')
 
         self.assertEqual(1, len(rows))
-        self.assertIn("Latest comment", unicode(rows[0]))
-        self.assertNotIn("Earlier comment", unicode(rows[0]))
+        self.assertIn("Latest comment", six.text_type(rows[0]))
+        self.assertNotIn("Earlier comment", six.text_type(rows[0]))
 
     def test_diff_row_links_to_extra_details(self):
         # The source package name links to the difference details.
diff --git a/lib/lp/registry/model/distroseries.py b/lib/lp/registry/model/distroseries.py
index 9ae85f4..d1940f3 100644
--- a/lib/lp/registry/model/distroseries.py
+++ b/lib/lp/registry/model/distroseries.py
@@ -18,6 +18,7 @@ from operator import attrgetter
 
 import apt_pkg
 from lazr.delegates import delegate_to
+import six
 from sqlobject import (
     BoolCol,
     ForeignKey,
@@ -321,7 +322,8 @@ class DistroSeries(SQLBase, BugTargetBase, HasSpecificationsMixin,
     @cachedproperty
     def suite_names(self):
         """See `IDistroSeries`."""
-        return [unicode(pocket) for pocket in PackagePublishingPocket.items]
+        return [
+            six.text_type(pocket) for pocket in PackagePublishingPocket.items]
 
     @property
     def answers_usage(self):
diff --git a/lib/lp/registry/model/distroseriesdifference.py b/lib/lp/registry/model/distroseriesdifference.py
index 3cdcd16..3f2e063 100644
--- a/lib/lp/registry/model/distroseriesdifference.py
+++ b/lib/lp/registry/model/distroseriesdifference.py
@@ -838,7 +838,7 @@ class DistroSeriesDifference(StormBase):
         if ancestry is not None and parent_ancestry is not None:
             intersection = ancestry.intersection(parent_ancestry)
             if len(intersection) > 0:
-                self.base_version = unicode(max(intersection))
+                self.base_version = six.text_type(max(intersection))
                 return True
         return False
 
diff --git a/lib/lp/registry/scripts/closeaccount.py b/lib/lp/registry/scripts/closeaccount.py
index b85acc5..fba057f 100644
--- a/lib/lp/registry/scripts/closeaccount.py
+++ b/lib/lp/registry/scripts/closeaccount.py
@@ -6,6 +6,7 @@
 __metaclass__ = type
 __all__ = ['CloseAccountScript']
 
+import six
 from storm.exceptions import IntegrityError
 from storm.expr import (
     LeftJoin,
@@ -466,7 +467,7 @@ class CloseAccountScript(LaunchpadScript):
 
         for username in self.args:
             try:
-                close_account(unicode(username), self.logger)
+                close_account(six.ensure_text(username), self.logger)
             except Exception:
                 self.txn.abort()
                 raise
diff --git a/lib/lp/registry/scripts/createbotaccount.py b/lib/lp/registry/scripts/createbotaccount.py
index 4a22fc4..d1419b8 100644
--- a/lib/lp/registry/scripts/createbotaccount.py
+++ b/lib/lp/registry/scripts/createbotaccount.py
@@ -3,6 +3,7 @@
 
 """Create a bot account."""
 
+import six
 from zope.component import getUtility
 
 from lp.registry.interfaces.person import IPersonSet
@@ -44,10 +45,10 @@ class CreateBotAccountScript(LaunchpadScript):
             help='Add bot to this comma separated list of teams')
 
     def main(self):
-        username = unicode(self.options.username)
+        username = six.ensure_text(self.options.username)
         if not username:
             raise LaunchpadScriptFailure('--username is required')
-        openid_suffix = unicode(self.options.openid)
+        openid_suffix = six.ensure_text(self.options.openid)
         if '/' in openid_suffix:
             raise LaunchpadScriptFailure(
                 'Invalid OpenID suffix {}'.format(openid_suffix))
@@ -55,18 +56,18 @@ class CreateBotAccountScript(LaunchpadScript):
         displayname = u'\U0001f916 {}'.format(username)  # U+1f916==ROBOT FACE
 
         if self.options.email:
-            emailaddress = unicode(self.options.email)
+            emailaddress = six.ensure_text(self.options.email)
         else:
             emailaddress = u'webops+{}@canonical.com'.format(username)
 
         if self.options.teams:
-            teamnames = [unicode(t.strip())
+            teamnames = [six.ensure_text(t.strip())
                          for t in self.options.teams.split(',')
                          if t.strip()]
         else:
             teamnames = []
 
-        sshkey_text = unicode(self.options.sshkey)  # Optional
+        sshkey_text = six.ensure_text(self.options.sshkey)  # Optional
 
         person_set = getUtility(IPersonSet)
 
diff --git a/lib/lp/registry/scripts/suspendbotaccount.py b/lib/lp/registry/scripts/suspendbotaccount.py
index a4cfcd1..7c0c903 100644
--- a/lib/lp/registry/scripts/suspendbotaccount.py
+++ b/lib/lp/registry/scripts/suspendbotaccount.py
@@ -3,6 +3,7 @@
 
 """Suspend a bot account."""
 
+import six
 from zope.component import getUtility
 
 from lp.registry.interfaces.person import IPersonSet
@@ -25,7 +26,7 @@ class SuspendBotAccountScript(LaunchpadScript):
             type='string', dest='email', default='', help='Email address')
 
     def main(self):
-        emailaddress = unicode(self.options.email)
+        emailaddress = six.ensure_text(self.options.email)
         if not emailaddress:
             raise LaunchpadScriptFailure('--email is required')
 
diff --git a/lib/lp/registry/services/tests/test_sharingservice.py b/lib/lp/registry/services/tests/test_sharingservice.py
index fee9288..50ce8c6 100644
--- a/lib/lp/registry/services/tests/test_sharingservice.py
+++ b/lib/lp/registry/services/tests/test_sharingservice.py
@@ -6,6 +6,7 @@ __metaclass__ = type
 
 from lazr.restful.interfaces import IWebBrowserOriginatingRequest
 from lazr.restful.utils import get_current_web_service_request
+import six
 from testtools.matchers import LessThan
 import transaction
 from zope.component import getUtility
@@ -96,7 +97,7 @@ class TestSharingService(TestCaseWithFactory):
         shared_items_exist = False
         permissions = {}
         for (policy, permission) in policy_permissions:
-            permissions[policy.name] = unicode(permission.name)
+            permissions[policy.name] = six.ensure_text(permission.name)
             if permission == SharingPermission.SOME:
                 shared_items_exist = True
         grantee_data['shared_items_exist'] = shared_items_exist
diff --git a/lib/lp/registry/vocabularies.py b/lib/lp/registry/vocabularies.py
index 78780a4..05e3900 100644
--- a/lib/lp/registry/vocabularies.py
+++ b/lib/lp/registry/vocabularies.py
@@ -2144,7 +2144,7 @@ class DistributionSourcePackageVocabulary(FilteredVocabularyBase):
         if not query:
             return EmptyResultSet()
 
-        query = unicode(query)
+        query = six.ensure_text(query)
         query_re = re.escape(query)
         store = IStore(DistributionSourcePackageInDatabase)
         # Construct the searchable text that could live in the DSP table.