← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:py3-bzr-format-strings into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:py3-bzr-format-strings into launchpad:master.

Commit message:
Treat bzr format strings as bytes

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

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

Breezy's get_format_string methods return bytes, so treat the return values as such.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-bzr-format-strings into launchpad:master.
diff --git a/lib/lp/code/bzr.py b/lib/lp/code/bzr.py
index fe1a7d8..ce51ca4 100644
--- a/lib/lp/code/bzr.py
+++ b/lib/lp/code/bzr.py
@@ -1,4 +1,4 @@
-# Copyright 2009-2014 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2020 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Enumerations relating to Bazaar formats."""
@@ -75,6 +75,7 @@ from lazr.enum import (
     DBEnumeratedType,
     DBItem,
     )
+import six
 
 
 def _format_enum(num, format, format_string=None, description=None):
@@ -83,7 +84,7 @@ def _format_enum(num, format, format_string=None, description=None):
         format_string = instance.get_format_string()
     if description is None:
         description = instance.get_format_description()
-    return DBItem(num, format_string, description)
+    return DBItem(num, six.ensure_str(format_string), description)
 
 
 class BazaarFormatEnum(DBEnumeratedType):
@@ -305,9 +306,11 @@ def get_branch_formats(bzr_branch):
 
     :returns: tuple of (ControlFormat, BranchFormat, RepositoryFormat)
     """
-    control_string = bzr_branch.controldir._format.get_format_string()
-    branch_string = bzr_branch._format.get_format_string()
-    repository_string = bzr_branch.repository._format.get_format_string()
+    control_string = six.ensure_str(
+        bzr_branch.controldir._format.get_format_string())
+    branch_string = six.ensure_str(bzr_branch._format.get_format_string())
+    repository_string = six.ensure_str(
+        bzr_branch.repository._format.get_format_string())
     return (ControlFormat.get_enum(control_string),
             BranchFormat.get_enum(branch_string),
             RepositoryFormat.get_enum(repository_string))
diff --git a/lib/lp/code/model/tests/test_branch.py b/lib/lp/code/model/tests/test_branch.py
index e2421ba..20c9ce7 100644
--- a/lib/lp/code/model/tests/test_branch.py
+++ b/lib/lp/code/model/tests/test_branch.py
@@ -397,7 +397,7 @@ class TestBranchWriteJobViaCelery(TestCaseWithFactory):
         db_branch, tree = create_knit(self)
         self.assertEqual(
             tree.branch.repository._format.get_format_string(),
-            'Bazaar-NG Knit Repository Format 1')
+            b'Bazaar-NG Knit Repository Format 1')
 
         with person_logged_in(db_branch.owner):
             db_branch.requestUpgrade(db_branch.owner)
@@ -406,7 +406,7 @@ class TestBranchWriteJobViaCelery(TestCaseWithFactory):
         new_branch = Branch.open(tree.branch.base)
         self.assertEqual(
             new_branch.repository._format.get_format_string(),
-            'Bazaar repository format 2a (needs bzr 1.16 or later)\n')
+            b'Bazaar repository format 2a (needs bzr 1.16 or later)\n')
         self.assertFalse(db_branch.needs_upgrading)
 
 
diff --git a/lib/lp/code/model/tests/test_branchjob.py b/lib/lp/code/model/tests/test_branchjob.py
index abfa01e..a6266e9 100644
--- a/lib/lp/code/model/tests/test_branchjob.py
+++ b/lib/lp/code/model/tests/test_branchjob.py
@@ -257,7 +257,7 @@ class TestBranchUpgradeJob(TestCaseWithFactory):
         db_branch, tree = create_knit(self)
         self.assertEqual(
             tree.branch.repository._format.get_format_string(),
-            'Bazaar-NG Knit Repository Format 1')
+            b'Bazaar-NG Knit Repository Format 1')
 
         job = BranchUpgradeJob.create(db_branch, self.factory.makePerson())
 
@@ -268,7 +268,7 @@ class TestBranchUpgradeJob(TestCaseWithFactory):
         new_branch = Branch.open(tree.branch.base)
         self.assertEqual(
             new_branch.repository._format.get_format_string(),
-            'Bazaar repository format 2a (needs bzr 1.16 or later)\n')
+            b'Bazaar repository format 2a (needs bzr 1.16 or later)\n')
 
         self.becomeDbUser(dbuser)
         self.assertFalse(db_branch.needs_upgrading)
@@ -302,7 +302,7 @@ class TestBranchUpgradeJob(TestCaseWithFactory):
         new_branch = Branch.open(tree.branch.base)
         self.assertEqual(
             new_branch.repository._format.get_format_string(),
-            'Bazaar repository format 2a (needs bzr 1.16 or later)\n')
+            b'Bazaar repository format 2a (needs bzr 1.16 or later)\n')
 
     def test_db_user_can_request_scan(self):
         # The database user that does the upgrade needs to be able to request
diff --git a/lib/lp/code/scripts/tests/test_upgrade_branches.py b/lib/lp/code/scripts/tests/test_upgrade_branches.py
index b95dc8b..c697c85 100644
--- a/lib/lp/code/scripts/tests/test_upgrade_branches.py
+++ b/lib/lp/code/scripts/tests/test_upgrade_branches.py
@@ -1,4 +1,4 @@
-# Copyright 2009-2012 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2020 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Test the upgrade_branches script."""
@@ -30,7 +30,7 @@ class TestUpgradeBranches(TestCaseWithFactory):
 
         self.assertEqual(
             target_tree.branch.repository._format.get_format_string(),
-            'Bazaar-NG Knit Repository Format 1')
+            b'Bazaar-NG Knit Repository Format 1')
 
         BranchUpgradeJob.create(target, self.factory.makePerson())
         transaction.commit()
@@ -45,7 +45,7 @@ class TestUpgradeBranches(TestCaseWithFactory):
         target_branch = BzrBranch.open(target_tree.branch.base)
         self.assertEqual(
             target_branch.repository._format.get_format_string(),
-            'Bazaar repository format 2a (needs bzr 1.16 or later)\n')
+            b'Bazaar repository format 2a (needs bzr 1.16 or later)\n')
 
     def test_upgrade_branches_packagebranch(self):
         """Test that upgrade_branches can upgrade package branches."""
@@ -58,7 +58,7 @@ class TestUpgradeBranches(TestCaseWithFactory):
 
         self.assertEqual(
             target_tree.branch.repository._format.get_format_string(),
-            'Bazaar-NG Knit Repository Format 1')
+            b'Bazaar-NG Knit Repository Format 1')
 
         BranchUpgradeJob.create(target, self.factory.makePerson())
         transaction.commit()
@@ -73,4 +73,4 @@ class TestUpgradeBranches(TestCaseWithFactory):
         target_branch = BzrBranch.open(target_tree.branch.base)
         self.assertEqual(
             target_branch.repository._format.get_format_string(),
-            'Bazaar repository format 2a (needs bzr 1.16 or later)\n')
+            b'Bazaar repository format 2a (needs bzr 1.16 or later)\n')
diff --git a/lib/lp/code/xmlrpc/tests/test_codehosting.py b/lib/lp/code/xmlrpc/tests/test_codehosting.py
index c5ec059..99a9cd1 100644
--- a/lib/lp/code/xmlrpc/tests/test_codehosting.py
+++ b/lib/lp/code/xmlrpc/tests/test_codehosting.py
@@ -1,4 +1,4 @@
-# Copyright 2009-2016 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2020 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Tests for the internal codehosting API."""
@@ -11,6 +11,7 @@ import os
 from breezy import controldir
 from breezy.urlutils import escape
 import pytz
+import six
 from testscenarios import (
     load_tests_apply_scenarios,
     WithScenarios,
@@ -660,10 +661,11 @@ class CodehostingTest(WithScenarios, TestCaseWithFactory):
 
     def getFormatStringsForFormatName(self, format_name):
         default_format = controldir.format_registry.get(format_name)()
-        control_string = default_format.get_format_string()
-        branch_string = default_format.get_branch_format().get_format_string()
-        repository_string = \
-            default_format.repository_format.get_format_string()
+        control_string = six.ensure_str(default_format.get_format_string())
+        branch_string = six.ensure_str(
+            default_format.get_branch_format().get_format_string())
+        repository_string = six.ensure_str(
+            default_format.repository_format.get_format_string())
         return (control_string, branch_string, repository_string)
 
     @property
diff --git a/lib/lp/codehosting/bzrutils.py b/lib/lp/codehosting/bzrutils.py
index e3f50fd..308bbe0 100644
--- a/lib/lp/codehosting/bzrutils.py
+++ b/lib/lp/codehosting/bzrutils.py
@@ -1,4 +1,4 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2020 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Utilities for dealing with Breezy.
@@ -55,6 +55,7 @@ from breezy.transport import (
     )
 from breezy.transport.local import LocalTransport
 from lazr.uri import URI
+import six
 
 from lp.services.webapp.errorlog import (
     ErrorReportingUtility,
@@ -327,9 +328,11 @@ def get_branch_info(branch):
     # XXX: Aaron Bentley 2008-06-13
     # Bazaar does not provide a public API for learning about
     # format markers.  Fix this in Bazaar, then here.
-    info['control_string'] = branch.controldir._format.get_format_string()
-    info['branch_string'] = branch._format.get_format_string()
-    info['repository_string'] = branch.repository._format.get_format_string()
+    info['control_string'] = six.ensure_str(
+        branch.controldir._format.get_format_string())
+    info['branch_string'] = six.ensure_str(branch._format.get_format_string())
+    info['repository_string'] = six.ensure_str(
+        branch.repository._format.get_format_string())
     return info
 
 
diff --git a/lib/lp/codehosting/puller/tests/test_scheduler.py b/lib/lp/codehosting/puller/tests/test_scheduler.py
index 738f76a..f87c78f 100644
--- a/lib/lp/codehosting/puller/tests/test_scheduler.py
+++ b/lib/lp/codehosting/puller/tests/test_scheduler.py
@@ -1,4 +1,4 @@
-# Copyright 2009-2018 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2020 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 from __future__ import absolute_import, print_function
@@ -13,6 +13,7 @@ from breezy.branch import Branch
 from breezy.bzr.bzrdir import BzrDir
 from breezy.controldir import format_registry
 from breezy.urlutils import join as urljoin
+import six
 from testtools.twistedsupport import (
     assert_fails_with,
     AsynchronousDeferredRunTest,
@@ -614,11 +615,11 @@ class TestPullerMasterIntegration(PullerBranchTestCase):
 
         def check_authserver_called(ignored):
             default_format = format_registry.get('default')()
-            control_string = default_format.get_format_string()
-            branch_string = \
-                default_format.get_branch_format().get_format_string()
-            repository_string = \
-                default_format.repository_format.get_format_string()
+            control_string = six.ensure_str(default_format.get_format_string())
+            branch_string = six.ensure_str(
+                default_format.get_branch_format().get_format_string())
+            repository_string = six.ensure_str(
+                default_format.repository_format.get_format_string())
             self.assertEqual(
                 [('branchChanged', LAUNCHPAD_SERVICES, self.db_branch.id, '',
                   revision_id, control_string, branch_string,
diff --git a/lib/lp/codehosting/puller/worker.py b/lib/lp/codehosting/puller/worker.py
index cdb7c5c..c0b426f 100644
--- a/lib/lp/codehosting/puller/worker.py
+++ b/lib/lp/codehosting/puller/worker.py
@@ -1,4 +1,4 @@
-# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2020 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 from __future__ import absolute_import, print_function
@@ -41,6 +41,7 @@ from lazr.uri import (
     InvalidURIError,
     URI,
     )
+import six
 from six.moves import http_client
 from six.moves.urllib.error import HTTPError
 
@@ -468,8 +469,9 @@ class PullerWorker:
             else:
                 repository_string = repository_format.get_format_string()
             self.protocol.branchChanged(
-                stacked_on_url, revid_before, revid_after, control_string,
-                branch_string, repository_string)
+                stacked_on_url, revid_before, revid_after,
+                six.ensure_str(control_string), six.ensure_str(branch_string),
+                six.ensure_str(repository_string))
 
     def __eq__(self, other):
         return self.source == other.source and self.dest == other.dest
diff --git a/lib/lp/codehosting/vfs/tests/test_branchfs.py b/lib/lp/codehosting/vfs/tests/test_branchfs.py
index 64cc6d9..d159450 100644
--- a/lib/lp/codehosting/vfs/tests/test_branchfs.py
+++ b/lib/lp/codehosting/vfs/tests/test_branchfs.py
@@ -1,4 +1,4 @@
-# Copyright 2009-2018 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2020 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Tests for the branch filesystem."""
@@ -37,6 +37,7 @@ from breezy.urlutils import (
     escape,
     local_path_to_url,
     )
+import six
 from six.moves import xmlrpc_client
 from testtools.twistedsupport import (
     assert_fails_with,
@@ -985,9 +986,11 @@ class TestBranchChangedNotification(TestCaseWithTransport):
 
     def assertFormatStringsPassed(self, branch):
         self.assertEqual(1, len(self._branch_changed_log))
-        control_string = branch.controldir._format.get_format_string()
-        branch_string = branch._format.get_format_string()
-        repository_string = branch.repository._format.get_format_string()
+        control_string = six.ensure_str(
+            branch.controldir._format.get_format_string())
+        branch_string = six.ensure_str(branch._format.get_format_string())
+        repository_string = six.ensure_str(
+            branch.repository._format.get_format_string())
         self.assertEqual(
             (control_string, branch_string, repository_string),
             self._branch_changed_log[0]['format_strings'])