← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:py3-pillar-remove-ensure-unicode into launchpad:master

 

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

Commit message:
Remove uses of ensure_unicode for pillars

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

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

It's deprecated, and in most cases nowadays we can either require Unicode input or use `six.ensure_text` instead.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-pillar-remove-ensure-unicode into launchpad:master.
diff --git a/lib/lp/registry/model/pillar.py b/lib/lp/registry/model/pillar.py
index 3482abb..e138952 100644
--- a/lib/lp/registry/model/pillar.py
+++ b/lib/lp/registry/model/pillar.py
@@ -11,6 +11,7 @@ __metaclass__ = type
 from operator import attrgetter
 import warnings
 
+import six
 from sqlobject import (
     BoolCol,
     ForeignKey,
@@ -54,7 +55,6 @@ from lp.services.database.sqlbase import (
     SQLBase,
     sqlvalues,
     )
-from lp.services.helpers import ensure_unicode
 from lp.services.librarian.model import LibraryFileAlias
 
 
@@ -91,7 +91,7 @@ class PillarNameSet:
 
     def __contains__(self, name):
         """See `IPillarNameSet`."""
-        name = ensure_unicode(name)
+        name = six.ensure_text(name)
         result = IStore(PillarName).execute("""
             SELECT TRUE
             FROM PillarName
@@ -134,7 +134,7 @@ class PillarNameSet:
             query %= " AND active IS TRUE"
         else:
             query %= ""
-        name = ensure_unicode(name)
+        name = six.ensure_text(name)
         result = IStore(PillarName).execute(query, [name, name])
         row = result.get_one()
         if row is None:
@@ -185,7 +185,7 @@ class PillarNameSet:
                  Distribution.fti @@ ftq(%(text)s) OR
                  lower(Distribution.title) = lower(%(text)s)
                 )
-            ''' % sqlvalues(text=ensure_unicode(text)))
+            ''' % sqlvalues(text=text))
         columns = [
             PillarName, OtherPillarName, Product, ProjectGroup, Distribution]
         return IStore(PillarName).using(*origin).find(
diff --git a/lib/lp/registry/vocabularies.py b/lib/lp/registry/vocabularies.py
index 24b5675..59242f0 100644
--- a/lib/lp/registry/vocabularies.py
+++ b/lib/lp/registry/vocabularies.py
@@ -313,7 +313,6 @@ class ProductVocabulary(SQLObjectVocabularyBase):
         if query is None or an empty string.
         """
         if query:
-            query = ensure_unicode(query)
             like_query = query.lower()
             like_query = "'%%%%' || %s || '%%%%'" % quote_like(like_query)
             fti_query = quote(query)
@@ -372,7 +371,6 @@ class ProjectGroupVocabulary(SQLObjectVocabularyBase):
         if query is None or an empty string.
         """
         if query:
-            query = ensure_unicode(query)
             like_query = query.lower()
             like_query = "'%%' || %s || '%%'" % quote_like(like_query)
             fti_query = quote(query)
@@ -1862,7 +1860,7 @@ class PillarVocabularyBase(NamedStormHugeVocabulary):
     def searchForTerms(self, query=None, vocab_filter=None):
         if not query:
             return self.emptySelectResults()
-        query = ensure_unicode(query).lower()
+        query = six.ensure_text(query).lower()
         store = IStore(PillarName)
         origin = [
             PillarName,