launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #25344
[Merge] ~cjwatson/launchpad:services-worlddata-future-imports into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:services-worlddata-future-imports into launchpad:master.
Commit message:
Convert lp.services.worlddata to preferred __future__ imports
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/391091
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:services-worlddata-future-imports into launchpad:master.
diff --git a/lib/lp/services/worlddata/browser/country.py b/lib/lp/services/worlddata/browser/country.py
index 61cb1be..0641ff1 100644
--- a/lib/lp/services/worlddata/browser/country.py
+++ b/lib/lp/services/worlddata/browser/country.py
@@ -1,6 +1,8 @@
# Copyright 2010 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, unicode_literals
+
from lp.services.webapp import GetitemNavigation
from lp.services.worlddata.interfaces.country import ICountrySet
diff --git a/lib/lp/services/worlddata/doc/language.txt b/lib/lp/services/worlddata/doc/language.txt
index fdca7f3..4e36fd2 100644
--- a/lib/lp/services/worlddata/doc/language.txt
+++ b/lib/lp/services/worlddata/doc/language.txt
@@ -24,12 +24,12 @@ canonicalise_language_code
We can convert language codes to standard form.
- >>> language_set.canonicalise_language_code('pt')
- 'pt'
- >>> language_set.canonicalise_language_code('pt_BR')
- 'pt_BR'
- >>> language_set.canonicalise_language_code('pt-br')
- 'pt_BR'
+ >>> print(language_set.canonicalise_language_code('pt'))
+ pt
+ >>> print(language_set.canonicalise_language_code('pt_BR'))
+ pt_BR
+ >>> print(language_set.canonicalise_language_code('pt-br'))
+ pt_BR
codes_to_languages
==================
@@ -50,9 +50,9 @@ createLanguage
This method creates a new language.
>>> foos = language_set.createLanguage('foos', 'Foo language')
- >>> print foos.code
+ >>> print(foos.code)
foos
- >>> print foos.englishname
+ >>> print(foos.englishname)
Foo language
search
@@ -62,7 +62,7 @@ We are able to search languages with this method.
>>> languages = language_set.search('Spanish')
>>> for language in languages:
- ... print language.code, language.englishname
+ ... print(language.code, language.englishname)
es Spanish
es_AR Spanish (Argentina)
es_BO Spanish (Bolivia)
@@ -90,7 +90,7 @@ It's case insensitive:
>>> languages = language_set.search('spanish')
>>> for language in languages:
- ... print language.code, language.englishname
+ ... print(language.code, language.englishname)
es Spanish
es_AR Spanish (Argentina)
es_BO Spanish (Bolivia)
@@ -118,7 +118,7 @@ And it even does substring searching!
>>> languages = language_set.search('panis')
>>> for language in languages:
- ... print language.code, language.englishname
+ ... print(language.code, language.englishname)
es Spanish
es_AR Spanish (Argentina)
es_BO Spanish (Bolivia)
@@ -147,14 +147,14 @@ matching any string:
>>> languages = language_set.search('%')
>>> for language in languages:
- ... print language.code, language.englishname
+ ... print(language.code, language.englishname)
Or '_', which means any character match, but we only get strings
that contain the 'e_' substring:
>>> languages = language_set.search('e_')
>>> for language in languages:
- ... print language.code, language.englishname
+ ... print(language.code, language.englishname)
de_AT German (Austria)
de_BE German (Belgium)
de_DE German (Germany)
@@ -177,23 +177,23 @@ second language. They might not be perfect but they are useful nonetheless.
pt_BR is not a descendent of pt:
>>> pt_BR = language_set.getLanguageByCode('pt_BR')
- >>> print pt_BR.alt_suggestion_language
+ >>> print(pt_BR.alt_suggestion_language)
None
However, es_MX would find es useful:
>>> language = language_set.getLanguageByCode('es_MX')
- >>> print language.alt_suggestion_language.code
+ >>> print(language.alt_suggestion_language.code)
es
And Nynorsk and Bokmal have a special relationship:
>>> language = language_set.getLanguageByCode('nn')
- >>> print language.alt_suggestion_language.code
+ >>> print(language.alt_suggestion_language.code)
nb
>>> language = language_set.getLanguageByCode('nb')
- >>> print language.alt_suggestion_language.code
+ >>> print(language.alt_suggestion_language.code)
nn
English and non-visible languages are not translatable, so there
@@ -224,7 +224,7 @@ represent, for instance pt_BR, when used on web pages, it should use
instead a dash char. This method does it automatically:
>>> pt_BR = language_set.getLanguageByCode('pt_BR')
- >>> print pt_BR.dashedcode
+ >>> print(pt_BR.dashedcode)
pt-BR
@@ -271,7 +271,7 @@ have the language among their preferred languages.
... karmavalue=40)
>>> switch_dbuser('launchpad')
>>> for translator in sr.translators:
- ... print translator.name
+ ... print(translator.name)
serbian-translator-karma-40
serbian-translator-karma-30
serbian-translator-karma-20
@@ -286,7 +286,7 @@ Property holding a list of countries a language is spoken in, and allowing
reading and setting them.
>>> es = language_set.getLanguageByCode('es')
- >>> print [country.name for country in es.countries]
+ >>> print([country.name for country in es.countries])
[u'Argentina', u'Bolivia', u'Chile', u'Colombia', u'Costa Rica',
u'Dominican Republic', u'Ecuador', u'El Salvador', u'Guatemala',
u'Honduras', u'Mexico', u'Nicaragua', u'Panama', u'Paraguay', u'Peru',
@@ -298,7 +298,7 @@ We can add countries using `ILanguage.addCountry` method.
>>> country_set = getUtility(ICountrySet)
>>> germany = country_set['DE']
>>> es.addCountry(germany)
- >>> print [country.name for country in es.countries]
+ >>> print([country.name for country in es.countries])
[u'Argentina', u'Bolivia', u'Chile', u'Colombia', u'Costa Rica',
u'Dominican Republic', u'Ecuador', u'El Salvador', u'Germany', u'Guatemala',
u'Honduras', u'Mexico', u'Nicaragua', u'Panama', u'Paraguay', u'Peru',
@@ -308,7 +308,7 @@ Or, we can remove countries using `ILanguage.removeCountry` method.
>>> argentina = country_set['AR']
>>> es.removeCountry(argentina)
- >>> print [country.name for country in es.countries]
+ >>> print([country.name for country in es.countries])
[u'Bolivia', u'Chile', u'Colombia', u'Costa Rica', u'Dominican Republic',
u'Ecuador', u'El Salvador', u'Germany', u'Guatemala', u'Honduras',
u'Mexico', u'Nicaragua', u'Panama', u'Paraguay', u'Peru', u'Puerto Rico',
@@ -319,5 +319,5 @@ but we need to log in as a translations administrator first.
>>> login('carlos@xxxxxxxxxxxxx')
>>> es.countries = set([argentina, germany])
- >>> print [country.name for country in es.countries]
+ >>> print([country.name for country in es.countries])
[u'Argentina', u'Germany']
diff --git a/lib/lp/services/worlddata/doc/vocabularies.txt b/lib/lp/services/worlddata/doc/vocabularies.txt
index 2800395..ab100ea 100644
--- a/lib/lp/services/worlddata/doc/vocabularies.txt
+++ b/lib/lp/services/worlddata/doc/vocabularies.txt
@@ -34,20 +34,20 @@ All the languages known by Launchpad.
>>> es = language_set['es']
>>> term = language_vocabulary.getTerm(es)
- >>> print term.token, term.value.displayname, term.title
+ >>> print(term.token, term.value.displayname, term.title)
es Spanish (es) Spanish (es)
>>> pt_BR = language_set['pt_BR']
>>> term = language_vocabulary.getTerm(pt_BR)
- >>> print term.token, term.value.displayname, term.title
+ >>> print(term.token, term.value.displayname, term.title)
pt_BR Portuguese (Brazil) (pt_BR) Portuguese (Brazil) (pt_BR)
>>> term = language_vocabulary.getTermByToken('es')
- >>> print term.token, term.value.displayname, term.title
+ >>> print(term.token, term.value.displayname, term.title)
es Spanish (es) Spanish (es)
>>> term = language_vocabulary.getTermByToken('pt_BR')
- >>> print term.token, term.value.displayname, term.title
+ >>> print(term.token, term.value.displayname, term.title)
pt_BR Portuguese (Brazil) (pt_BR) Portuguese (Brazil) (pt_BR)
A language token/code may not be used with 'in' tests.
@@ -81,20 +81,20 @@ when the language is not English and is visible.
>>> es = language_set['es']
>>> term = translatable_language_vocabulary.getTerm(es)
- >>> print term.token, term.value.displayname, term.title
+ >>> print(term.token, term.value.displayname, term.title)
es Spanish (es) Spanish (es)
>>> pt_BR = language_set['pt_BR']
>>> term = translatable_language_vocabulary.getTerm(pt_BR)
- >>> print term.token, term.value.displayname, term.title
+ >>> print(term.token, term.value.displayname, term.title)
pt_BR Portuguese (Brazil) (pt_BR) Portuguese (Brazil) (pt_BR)
>>> term = translatable_language_vocabulary.getTermByToken('es')
- >>> print term.token, term.value.displayname, term.title
+ >>> print(term.token, term.value.displayname, term.title)
es Spanish (es) Spanish (es)
>>> term = translatable_language_vocabulary.getTermByToken('pt_BR')
- >>> print term.token, term.value.displayname, term.title
+ >>> print(term.token, term.value.displayname, term.title)
pt_BR Portuguese (Brazil) (pt_BR) Portuguese (Brazil) (pt_BR)
>>> es in translatable_language_vocabulary
diff --git a/lib/lp/services/worlddata/helpers.py b/lib/lp/services/worlddata/helpers.py
index 18c38c4..4c7643d 100644
--- a/lib/lp/services/worlddata/helpers.py
+++ b/lib/lp/services/worlddata/helpers.py
@@ -3,6 +3,8 @@
"""Worlddata helper functions."""
+from __future__ import absolute_import, print_function, unicode_literals
+
__metaclass__ = type
__all__ = [
'browser_languages',
diff --git a/lib/lp/services/worlddata/interfaces/country.py b/lib/lp/services/worlddata/interfaces/country.py
index a7e087a..1ded91a 100644
--- a/lib/lp/services/worlddata/interfaces/country.py
+++ b/lib/lp/services/worlddata/interfaces/country.py
@@ -3,6 +3,8 @@
"""Country interfaces."""
+from __future__ import absolute_import, print_function, unicode_literals
+
__metaclass__ = type
__all__ = [
diff --git a/lib/lp/services/worlddata/interfaces/language.py b/lib/lp/services/worlddata/interfaces/language.py
index a283c97..c2ba6af 100644
--- a/lib/lp/services/worlddata/interfaces/language.py
+++ b/lib/lp/services/worlddata/interfaces/language.py
@@ -3,6 +3,8 @@
"""Language interfaces."""
+from __future__ import absolute_import, print_function, unicode_literals
+
__metaclass__ = type
__all__ = [
diff --git a/lib/lp/services/worlddata/interfaces/spokenin.py b/lib/lp/services/worlddata/interfaces/spokenin.py
index d9d5818..6546067 100644
--- a/lib/lp/services/worlddata/interfaces/spokenin.py
+++ b/lib/lp/services/worlddata/interfaces/spokenin.py
@@ -5,6 +5,8 @@
countries..
"""
+from __future__ import absolute_import, print_function, unicode_literals
+
__metaclass__ = type
__all__ = ['ISpokenIn']
diff --git a/lib/lp/services/worlddata/interfaces/timezone.py b/lib/lp/services/worlddata/interfaces/timezone.py
index 435e503..25ed2ab 100644
--- a/lib/lp/services/worlddata/interfaces/timezone.py
+++ b/lib/lp/services/worlddata/interfaces/timezone.py
@@ -1,6 +1,8 @@
# Copyright 2009 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, unicode_literals
+
__metaclass__ = type
__all__ = [
'ITimezoneNameVocabulary',
diff --git a/lib/lp/services/worlddata/interfaces/webservice.py b/lib/lp/services/worlddata/interfaces/webservice.py
index 009ffca..dc3b900 100644
--- a/lib/lp/services/worlddata/interfaces/webservice.py
+++ b/lib/lp/services/worlddata/interfaces/webservice.py
@@ -9,6 +9,8 @@ There is a declaration in ZCML somewhere that looks like:
which tells `lazr.restful` that it should look for webservice exports here.
"""
+from __future__ import absolute_import, print_function, unicode_literals
+
__all__ = [
'ICountry',
'ICountrySet',
diff --git a/lib/lp/services/worlddata/model/country.py b/lib/lp/services/worlddata/model/country.py
index 55ca6dd..387a84a 100644
--- a/lib/lp/services/worlddata/model/country.py
+++ b/lib/lp/services/worlddata/model/country.py
@@ -1,9 +1,12 @@
# Copyright 2009 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, unicode_literals
+
__metaclass__ = type
__all__ = ['Country', 'CountrySet', 'Continent']
+import six
from sqlobject import (
ForeignKey,
SQLRelatedJoin,
@@ -42,8 +45,8 @@ class Country(SQLBase):
continent = ForeignKey(
dbName='continent', foreignKey='Continent', default=None)
languages = SQLRelatedJoin(
- 'Language', joinColumn='country', otherColumn='language',
- intermediateTable='SpokenIn')
+ six.ensure_str('Language'), joinColumn='country',
+ otherColumn='language', intermediateTable='SpokenIn')
@implementer(ICountrySet)
diff --git a/lib/lp/services/worlddata/model/language.py b/lib/lp/services/worlddata/model/language.py
index 245a686..9142207 100644
--- a/lib/lp/services/worlddata/model/language.py
+++ b/lib/lp/services/worlddata/model/language.py
@@ -2,6 +2,8 @@
# the GNU Affero General Public License version 3 (see the file
# LICENSE).
+from __future__ import absolute_import, print_function, unicode_literals
+
__metaclass__ = type
__all__ = [
'Language',
@@ -67,12 +69,12 @@ class Language(SQLBase):
default=TextDirection.LTR)
translation_teams = SQLRelatedJoin(
- 'Person', joinColumn="language",
+ six.ensure_str('Person'), joinColumn="language",
intermediateTable='Translator', otherColumn='translator')
_countries = SQLRelatedJoin(
- 'Country', joinColumn='language', otherColumn='country',
- intermediateTable='SpokenIn')
+ six.ensure_str('Country'), joinColumn='language',
+ otherColumn='country', intermediateTable='SpokenIn')
# Define a read/write property `countries` so it can be passed
# to language administration `LaunchpadFormView`.
diff --git a/lib/lp/services/worlddata/model/spokenin.py b/lib/lp/services/worlddata/model/spokenin.py
index ab51568..6d2f06c 100644
--- a/lib/lp/services/worlddata/model/spokenin.py
+++ b/lib/lp/services/worlddata/model/spokenin.py
@@ -1,6 +1,8 @@
# Copyright 2009 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, unicode_literals
+
__metaclass__ = type
__all__ = ['SpokenIn']
diff --git a/lib/lp/services/worlddata/stories/webservice/xx-country.txt b/lib/lp/services/worlddata/stories/webservice/xx-country.txt
index 05d8db0..d2aba2d 100644
--- a/lib/lp/services/worlddata/stories/webservice/xx-country.txt
+++ b/lib/lp/services/worlddata/stories/webservice/xx-country.txt
@@ -4,7 +4,7 @@ At the top level we provide the collection of all countries.
>>> countries = webservice.get("/+countries").jsonBody()
>>> for entry in countries['entries']:
- ... print entry['self_link']
+ ... print(entry['self_link'])
http://.../+countries/AD
http://.../+countries/AE
http://.../+countries/AF
@@ -28,7 +28,7 @@ And for every country we publish most of its attributes.
Make sure that invalid countries return 404s and not OOPSes.
>>> bogus_country = "http://api.launchpad.test/beta/+countries/bogus"
- >>> print webservice.get(bogus_country)
+ >>> print(webservice.get(bogus_country))
HTTP/1.1 404 Not Found
...
Object: ..., name: u'bogus'
@@ -40,7 +40,7 @@ Make sure that invalid countries return 404s and not OOPSes.
>>> uk = webservice.named_get(
... '/+countries', 'getByName',
... name='United Kingdom').jsonBody()
- >>> print uk['self_link']
+ >>> print(uk['self_link'])
http://.../+countries/GB
Ensure that unknown/non-existent countries return a None and not an OOPS:
@@ -48,7 +48,7 @@ Ensure that unknown/non-existent countries return a None and not an OOPS:
>>> bogus_country_by_name = webservice.named_get(
... '/+countries', 'getByName',
... name='Klingon Land').jsonBody()
- >>> print bogus_country_by_name
+ >>> print(bogus_country_by_name)
None
@@ -57,7 +57,7 @@ Ensure that unknown/non-existent countries return a None and not an OOPS:
>>> au = webservice.named_get(
... '/+countries', 'getByCode',
... code='AU').jsonBody()
- >>> print au['self_link']
+ >>> print(au['self_link'])
http://.../+countries/AU
Ensure that unknown/non-existent country codes return a None and not an OOPS:
@@ -65,5 +65,5 @@ Ensure that unknown/non-existent country codes return a None and not an OOPS:
>>> bogus_country_by_code = webservice.named_get(
... '/+countries', 'getByCode',
... code='TEST').jsonBody()
- >>> print bogus_country_by_code
+ >>> print(bogus_country_by_code)
None
diff --git a/lib/lp/services/worlddata/stories/webservice/xx-language.txt b/lib/lp/services/worlddata/stories/webservice/xx-language.txt
index 05401ce..56484ae 100644
--- a/lib/lp/services/worlddata/stories/webservice/xx-language.txt
+++ b/lib/lp/services/worlddata/stories/webservice/xx-language.txt
@@ -10,19 +10,19 @@ The language information from Launchpad can be queried using
>>> es = anon_webservice.get('/+languages/es').jsonBody()
>>> es['resource_type_link']
u'http.../#language'
- >>> print es['text_direction']
+ >>> print(es['text_direction'])
Left to Right
- >>> print es['code']
+ >>> print(es['code'])
es
- >>> print es['english_name']
+ >>> print(es['english_name'])
Spanish
- >>> print es['plural_expression']
+ >>> print(es['plural_expression'])
n != 1
- >>> print es['plural_forms']
+ >>> print(es['plural_forms'])
2
- >>> print es['translators_count']
+ >>> print(es['translators_count'])
1
- >>> print es['visible']
+ >>> print(es['visible'])
True
@@ -45,7 +45,7 @@ at '/+languages'.
>>> default_languages['resource_type_link']
u'http.../#languages'
>>> languages = get_languages_entries(default_languages)
- >>> print languages
+ >>> print(languages)
Abkhazian
...
>>> '(hidden)' in languages
@@ -60,7 +60,7 @@ default.
... '/+languages?'
... 'ws.op=getAllLanguages&ws.start=0&ws.size=10'
... ).jsonBody()
- >>> print get_languages_entries(all_languages)
+ >>> print(get_languages_entries(all_languages))
Abkhazian
...
Afar (Djibouti)(hidden)
diff --git a/lib/lp/services/worlddata/tests/test_doc.py b/lib/lp/services/worlddata/tests/test_doc.py
index 3754618..39f6412 100644
--- a/lib/lp/services/worlddata/tests/test_doc.py
+++ b/lib/lp/services/worlddata/tests/test_doc.py
@@ -5,10 +5,13 @@
Run the doctests and pagetests.
"""
+from __future__ import absolute_import, print_function, unicode_literals
+
import os
from lp.services.testing import build_test_suite
from lp.testing.layers import LaunchpadZopelessLayer
+from lp.testing.pages import setUpGlobs
from lp.testing.systemdocs import (
LayeredDocFileSuite,
setUp,
@@ -21,9 +24,11 @@ special = {
'language.txt': LayeredDocFileSuite(
'../doc/language.txt',
layer=LaunchpadZopelessLayer,
- setUp=setUp, tearDown=tearDown),
+ setUp=lambda test: setUp(test, future=True), tearDown=tearDown),
}
def test_suite():
- return build_test_suite(here, special)
+ return build_test_suite(
+ here, special, setUp=lambda test: setUp(test, future=True),
+ pageTestsSetUp=lambda test: setUpGlobs(test, future=True))
diff --git a/lib/lp/services/worlddata/tests/test_helpers.py b/lib/lp/services/worlddata/tests/test_helpers.py
index a129604..a3b8429 100644
--- a/lib/lp/services/worlddata/tests/test_helpers.py
+++ b/lib/lp/services/worlddata/tests/test_helpers.py
@@ -1,6 +1,8 @@
# Copyright 2011 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, unicode_literals
+
from doctest import DocTestSuite
import unittest
@@ -119,8 +121,8 @@ def test_preferred_or_request_languages():
>>> languages = preferred_or_request_languages(DummyRequest())
>>> len(languages)
1
- >>> languages[0].code
- 'es'
+ >>> print(languages[0].code)
+ es
>>> tearDown()
@@ -141,8 +143,8 @@ def test_preferred_or_request_languages():
>>> languages = preferred_or_request_languages(DummyRequest())
>>> len(languages)
6
- >>> languages[0].code
- 'ja'
+ >>> print(languages[0].code)
+ ja
>>> tearDown()
'''
diff --git a/lib/lp/services/worlddata/tests/test_language.py b/lib/lp/services/worlddata/tests/test_language.py
index b5eafea..797d3d2 100644
--- a/lib/lp/services/worlddata/tests/test_language.py
+++ b/lib/lp/services/worlddata/tests/test_language.py
@@ -1,6 +1,8 @@
# Copyright 2010 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, unicode_literals
+
__metaclass__ = type
from lazr.lifecycle.interfaces import IDoNotSnapshot