← Back to team overview

launchpad-reviewers team mailing list archive

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

 

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

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

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

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

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-soyuz-unicode into launchpad:master.
diff --git a/lib/lp/soyuz/model/archive.py b/lib/lp/soyuz/model/archive.py
index dd80d33..529dc7a 100644
--- a/lib/lp/soyuz/model/archive.py
+++ b/lib/lp/soyuz/model/archive.py
@@ -1983,7 +1983,7 @@ class Archive(SQLBase):
         reason = self.checkUploadToPocket(series, pocket, person=person)
         if reason:
             # Wrap any forbidden-pocket error in CannotCopy.
-            raise CannotCopy(unicode(reason))
+            raise CannotCopy(six.text_type(reason))
 
         # Perform the copy, may raise CannotCopy. Don't do any further
         # permission checking: this method is protected by
diff --git a/lib/lp/soyuz/model/binarypackagebuild.py b/lib/lp/soyuz/model/binarypackagebuild.py
index 998682a..8561e70 100644
--- a/lib/lp/soyuz/model/binarypackagebuild.py
+++ b/lib/lp/soyuz/model/binarypackagebuild.py
@@ -22,6 +22,7 @@ import warnings
 import apt_pkg
 from debian.deb822 import PkgRelation
 import pytz
+import six
 from sqlobject import SQLObjectNotFound
 from storm.expr import (
     And,
@@ -650,7 +651,7 @@ class BinaryPackageBuild(PackageBuildMixin, SQLBase):
                 remaining_deps.append(or_dep)
 
         # Update dependencies line
-        self.dependencies = unicode(PkgRelation.str(remaining_deps))
+        self.dependencies = six.ensure_text(PkgRelation.str(remaining_deps))
 
     def __getitem__(self, name):
         return self.getBinaryPackageRelease(name)
diff --git a/lib/lp/soyuz/model/initializedistroseriesjob.py b/lib/lp/soyuz/model/initializedistroseriesjob.py
index f7bbfd1..988c9cd 100644
--- a/lib/lp/soyuz/model/initializedistroseriesjob.py
+++ b/lib/lp/soyuz/model/initializedistroseriesjob.py
@@ -7,6 +7,7 @@ __all__ = [
     "InitializeDistroSeriesJob",
 ]
 
+import six
 from zope.interface import (
     implementer,
     provider,
@@ -218,7 +219,8 @@ class InitializeDistroSeriesJob(DistributionJobDerived):
         # This method is called when error is an instance of
         # self.user_error_types.
         super(InitializeDistroSeriesJob, self).notifyUserError(error)
-        self.metadata = dict(self.metadata, error_description=unicode(error))
+        self.metadata = dict(
+            self.metadata, error_description=six.text_type(error))
 
     def getOopsVars(self):
         """See `IRunnableJob`."""
diff --git a/lib/lp/soyuz/model/packagecopyjob.py b/lib/lp/soyuz/model/packagecopyjob.py
index 90389e9..b07b88d 100644
--- a/lib/lp/soyuz/model/packagecopyjob.py
+++ b/lib/lp/soyuz/model/packagecopyjob.py
@@ -147,7 +147,7 @@ class PackageCopyJob(StormBase):
         self.source_archive = source_archive
         self.target_archive = target_archive
         self.target_distroseries = target_distroseries
-        self.package_name = unicode(package_name)
+        self.package_name = six.ensure_text(package_name)
         self.copy_policy = copy_policy
         self.metadata = metadata
 
@@ -589,7 +589,7 @@ class PlainPackageCopyJob(PackageCopyJobDerived):
             target_archive_purpose = self.target_archive.purpose
             self.logger.info("Job:\n%s\nraised CannotCopy:\n%s" % (self, e))
             self.abort()  # Abort the txn.
-            self.reportFailure(unicode(e))
+            self.reportFailure(six.text_type(e))
 
             # If there is an associated PackageUpload we need to reject it,
             # else it will sit in ACCEPTED forever.
@@ -628,7 +628,7 @@ class PlainPackageCopyJob(PackageCopyJobDerived):
             person=self.requester)
         if reason:
             # Wrap any forbidden-pocket error in CannotCopy.
-            raise CannotCopy(unicode(reason))
+            raise CannotCopy(six.text_type(reason))
 
         if self.silent and not self.requester_can_admin_target:
             raise CannotCopy(
diff --git a/lib/lp/soyuz/model/sourcepackagerelease.py b/lib/lp/soyuz/model/sourcepackagerelease.py
index c01e2e7..70261aa 100644
--- a/lib/lp/soyuz/model/sourcepackagerelease.py
+++ b/lib/lp/soyuz/model/sourcepackagerelease.py
@@ -20,6 +20,7 @@ from debian.changelog import (
     ChangelogParseError,
     )
 import pytz
+import six
 from sqlobject import (
     ForeignKey,
     SQLMultipleJoin,
@@ -172,7 +173,7 @@ class SourcePackageRelease(SQLBase):
         store = Store.of(self)
         store.flush()
         if content is not None:
-            content = unicode(content)
+            content = six.ensure_text(content)
         store.execute(
             "UPDATE sourcepackagerelease SET copyright=%s WHERE id=%s",
             (content, self.id))
diff --git a/lib/lp/soyuz/scripts/populate_archive.py b/lib/lp/soyuz/scripts/populate_archive.py
index b853d49..fc0dbfd 100644
--- a/lib/lp/soyuz/scripts/populate_archive.py
+++ b/lib/lp/soyuz/scripts/populate_archive.py
@@ -231,7 +231,7 @@ class ArchivePopulator(SoyuzScript):
         # archive population parameters in the database.
         pcr = getUtility(IPackageCopyRequestSet).new(
             the_origin, the_destination, registrant,
-            copy_binaries=include_binaries, reason=unicode(reason))
+            copy_binaries=include_binaries, reason=six.ensure_text(reason))
 
         # Clone the source packages. We currently do not support the copying
         # of binary packages. It's a forthcoming feature.