launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #00971
[Merge] lp:~sinzui/launchpad/dedup-preferred-launguages-0 into lp:launchpad/devel
Curtis Hovey has proposed merging lp:~sinzui/launchpad/dedup-preferred-launguages-0 into lp:launchpad/devel.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
Related bugs:
#159146 OOPS setting account as answer contact
https://bugs.launchpad.net/bugs/159146
#636453 move geoip code to lp.services
https://bugs.launchpad.net/bugs/636453
This is my branch to move geoip to lp.services so that I can fix a bug.
lp:~sinzui/launchpad/dedup-preferred-launguages-0
Diff size: 512
Launchpad bug:
https://bugs.launchpad.net/bugs/636453
Test command: ./bin/test -vv -m geoip
Pre-implementation: no one
Target release: 10.10
Move geoip to lp.services
-------------------------
The fix for the duplicate preferred language requires a change to the
geoip module which is in a deprecated location. The code should be migrated
before the fix is made.
Rules
-----
* Move geoip to lp.services.geoip.
* Move geoip's components to lp.services.geoip.helpers
QA
--
* View your preferred languages.
* Verify the page states your browser and location languages.
Lint
----
Linting changed files:
lib/canonical/launchpad/configure.zcml
lib/canonical/launchpad/helpers.py
lib/canonical/launchpad/interfaces/__init__.py
lib/canonical/launchpad/zcml/configure.zcml
lib/canonical/widgets/location.py
lib/lp/registry/browser/distribution.py
lib/lp/registry/browser/person.py
lib/lp/services/configure.zcml
lib/lp/services/geoip/
lib/lp/services/apachelogparser/base.py
lib/lp/services/geoip/__init__.py
lib/lp/services/geoip/configure.zcml
lib/lp/services/geoip/doc/
lib/lp/services/geoip/helpers.py
lib/lp/services/geoip/model.py
lib/lp/services/geoip/tests/
lib/lp/services/geoip/doc/geoip.txt
lib/lp/services/geoip/tests/test_doc.py
lib/lp/services/geoip/tests/test_request_country.py
lib/lp/translations/browser/translations.py
lib/lp/translations/doc/preferred-languages.txt
Test
----
No test changes, but I renamed test_request_country.py to test_doc.py and
revised it to run doctests from the doc dir and inline doctests from the
module.
Implementation
--------------
The is mostly mechanical changes to import or stylistic changes to quiet
lint. Note that I consilodated the lp.services ZCML registrations in
lib/lp/services/configure.zcml.
--
https://code.launchpad.net/~sinzui/launchpad/dedup-preferred-launguages-0/+merge/35228
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~sinzui/launchpad/dedup-preferred-launguages-0 into lp:launchpad/devel.
=== modified file 'lib/canonical/launchpad/configure.zcml'
--- lib/canonical/launchpad/configure.zcml 2010-08-17 13:58:57 +0000
+++ lib/canonical/launchpad/configure.zcml 2010-09-12 16:06:00 +0000
@@ -31,8 +31,6 @@
<include package="lp.translations" />
<include package="lp.testopenid" />
<include package="lp.blueprints" />
- <include package="lp.services.comments" />
- <include package="lp.services.fields" />
<include package="lp.vostok" />
<browser:url
=== modified file 'lib/canonical/launchpad/helpers.py'
--- lib/canonical/launchpad/helpers.py 2010-08-20 20:31:18 +0000
+++ lib/canonical/launchpad/helpers.py 2010-09-12 16:06:00 +0000
@@ -25,18 +25,18 @@
from zope.security.interfaces import ForbiddenAttribute
import canonical
-from canonical.launchpad.interfaces import (
- ILaunchBag,
+from canonical.launchpad.interfaces import ILaunchBag
+from lp.services.geoip.interfaces import (
IRequestLocalLanguages,
IRequestPreferredLanguages,
)
-# pylint: disable-msg=W0102
+
def text_replaced(text, replacements, _cache={}):
"""Return a new string with text replaced according to the dict provided.
- The keys of the dict are substrings to find, the values are what to replace
- found substrings with.
+ The keys of the dict are substrings to find, the values are what to
+ replace found substrings with.
:arg text: An unicode or str to do the replacement.
:arg replacements: A dictionary with the replacements that should be done
@@ -78,13 +78,16 @@
# Make a copy of the replacements dict, as it is mutable, but we're
# keeping a cached reference to it.
replacements_copy = dict(replacements)
+
def matchobj_replacer(matchobj):
return replacements_copy[matchobj.group()]
+
regexsub = re.compile(join_char.join(L)).sub
+
def replacer(s):
return regexsub(matchobj_replacer, s)
+
_cache[cachekey] = replacer
-
return _cache[cachekey](text)
@@ -98,7 +101,7 @@
def join_lines(*lines):
"""Concatenate a list of strings, adding a newline at the end of each."""
- return ''.join([ x + '\n' for x in lines ])
+ return ''.join([x + '\n' for x in lines])
def string_to_tarfile(s):
@@ -169,7 +172,7 @@
in the database.
"""
# All chars should be lower case, underscores and spaces become dashes.
- return text_replaced(invalid_name.lower(), {'_': '-', ' ':'-'})
+ return text_replaced(invalid_name.lower(), {'_': '-', ' ': '-'})
def browserLanguages(request):
@@ -193,8 +196,7 @@
p = subprocess.Popen(
command, env=env, stdin=subprocess.PIPE,
- stdout=subprocess.PIPE, stderr=subprocess.STDOUT
- )
+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
(output, nothing) = p.communicate(input)
return output
@@ -247,7 +249,7 @@
3: {'.': ' (!) ',
'@': ' (at) '},
4: {'.': ' {dot} ',
- '@': ' {at} '}
+ '@': ' {at} '},
}
@@ -444,12 +446,13 @@
>>> filenameToContentType('test.tgz')
'application/octet-stream'
"""
- ftmap = {".dsc": "text/plain",
- ".changes": "text/plain",
- ".deb": "application/x-debian-package",
- ".udeb": "application/x-debian-package",
- ".txt": "text/plain",
- ".txt.gz": "text/plain", # For the build master logs
+ ftmap = {".dsc": "text/plain",
+ ".changes": "text/plain",
+ ".deb": "application/x-debian-package",
+ ".udeb": "application/x-debian-package",
+ ".txt": "text/plain",
+ # For the build master logs
+ ".txt.gz": "text/plain",
}
for ending in ftmap:
if fname.endswith(ending):
=== modified file 'lib/canonical/launchpad/interfaces/__init__.py'
--- lib/canonical/launchpad/interfaces/__init__.py 2010-08-20 12:42:25 +0000
+++ lib/canonical/launchpad/interfaces/__init__.py 2010-09-12 16:06:00 +0000
@@ -71,7 +71,6 @@
from lp.bugs.interfaces.externalbugtracker import *
from lp.registry.interfaces.featuredproject import *
from lp.soyuz.interfaces.files import *
-from canonical.launchpad.interfaces.geoip import *
from lp.registry.interfaces.gpg import *
from canonical.launchpad.interfaces.gpghandler import *
from lp.hardwaredb.interfaces.hwdb import *
=== modified file 'lib/canonical/launchpad/zcml/configure.zcml'
--- lib/canonical/launchpad/zcml/configure.zcml 2010-08-11 15:47:27 +0000
+++ lib/canonical/launchpad/zcml/configure.zcml 2010-09-12 16:06:00 +0000
@@ -37,7 +37,6 @@
<!-- Event configuration -->
<!-- Special Utilities -->
- <include file="geoip.zcml" />
<include file="gpghandler.zcml" />
<include file="searchservice.zcml" />
=== modified file 'lib/canonical/widgets/location.py'
--- lib/canonical/widgets/location.py 2010-07-15 10:55:27 +0000
+++ lib/canonical/widgets/location.py 2010-09-12 16:06:00 +0000
@@ -24,12 +24,12 @@
from canonical.config import config
from canonical.launchpad import _
-from canonical.launchpad.interfaces.geoip import IGeoIPRecord
-from lp.registry.interfaces.location import IObjectWithLocation
from canonical.launchpad.validators import LaunchpadValidationError
from canonical.launchpad.webapp.interfaces import (
ILaunchBag, IMultiLineWidgetLayout)
from canonical.launchpad.webapp.tales import ObjectImageDisplayAPI
+from lp.registry.interfaces.location import IObjectWithLocation
+from lp.services.geoip.interfaces import IGeoIPRecord
class ILocationWidget(IInputWidget, IBrowserWidget, IMultiLineWidgetLayout):
=== modified file 'lib/lp/registry/browser/distribution.py'
--- lib/lp/registry/browser/distribution.py 2010-09-10 13:29:42 +0000
+++ lib/lp/registry/browser/distribution.py 2010-09-12 16:06:00 +0000
@@ -48,10 +48,6 @@
from canonical.launchpad.components.decoratedresultset import (
DecoratedResultSet,
)
-from canonical.launchpad.components.request_country import (
- ipaddress_from_request,
- request_country,
- )
from canonical.launchpad.helpers import english_list
from canonical.launchpad.webapp import (
action,
@@ -109,6 +105,10 @@
)
from lp.registry.interfaces.product import IProduct
from lp.registry.interfaces.series import SeriesStatus
+from lp.services.geoip.helpers import (
+ ipaddress_from_request,
+ request_country,
+ )
from lp.services.propertycache import cachedproperty
from lp.soyuz.browser.packagesearch import PackageSearchViewBase
from lp.soyuz.enums import ArchivePurpose
=== modified file 'lib/lp/registry/browser/person.py'
--- lib/lp/registry/browser/person.py 2010-09-10 12:24:03 +0000
+++ lib/lp/registry/browser/person.py 2010-09-12 16:06:00 +0000
@@ -159,7 +159,6 @@
IEmailAddress,
IEmailAddressSet,
)
-from canonical.launchpad.interfaces.geoip import IRequestPreferredLanguages
from canonical.launchpad.interfaces.gpghandler import (
GPGKeyNotFoundError,
IGPGHandler,
@@ -300,6 +299,7 @@
IWikiNameSet,
)
from lp.services.fields import LocationField
+from lp.services.geoip.interfaces import IRequestPreferredLanguages
from lp.services.openid.adapters.openid import CurrentOpenIDEndPoint
from lp.services.openid.browser.openiddiscovery import (
XRDSContentNegotiationMixin,
=== modified file 'lib/lp/services/apachelogparser/base.py'
--- lib/lp/services/apachelogparser/base.py 2010-08-30 17:12:59 +0000
+++ lib/lp/services/apachelogparser/base.py 2010-09-12 16:06:00 +0000
@@ -11,13 +11,13 @@
from zope.component import getUtility
from canonical.config import config
-from canonical.launchpad.interfaces.geoip import IGeoIP
from canonical.launchpad.webapp.interfaces import (
DEFAULT_FLAVOR,
IStoreSelector,
MAIN_STORE,
)
from lp.services.apachelogparser.model.parsedapachelog import ParsedApacheLog
+from lp.services.geoip.interfaces import IGeoIP
parser = apachelog.parser(apachelog.formats['extended'])
=== modified file 'lib/lp/services/configure.zcml'
--- lib/lp/services/configure.zcml 2010-08-20 12:11:28 +0000
+++ lib/lp/services/configure.zcml 2010-09-12 16:06:00 +0000
@@ -6,8 +6,11 @@
<adapter factory=".propertycache.get_default_cache"/>
<adapter factory=".propertycache.PropertyCacheManager"/>
<adapter factory=".propertycache.DefaultPropertyCacheManager"/>
+ <include package=".comments" />
<include package=".database" />
<include package=".features" />
+ <include package=".fields" />
+ <include package=".geoip" />
<include package=".inlinehelp" file="meta.zcml" />
<include package=".job" />
<include package=".memcache" />
=== added directory 'lib/lp/services/geoip'
=== added file 'lib/lp/services/geoip/__init__.py'
--- lib/lp/services/geoip/__init__.py 1970-01-01 00:00:00 +0000
+++ lib/lp/services/geoip/__init__.py 2010-09-12 16:06:00 +0000
@@ -0,0 +1,3 @@
+# Copyright 2010 Canonical Ltd. This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+"""Launchpad integration of the GEOIP library."""
=== renamed file 'lib/canonical/launchpad/zcml/geoip.zcml' => 'lib/lp/services/geoip/configure.zcml'
--- lib/canonical/launchpad/zcml/geoip.zcml 2009-07-13 18:15:02 +0000
+++ lib/lp/services/geoip/configure.zcml 2010-09-12 16:06:00 +0000
@@ -1,4 +1,4 @@
-<!-- Copyright 2009 Canonical Ltd. This software is licensed under the
+<!-- Copyright 2009-2010 Canonical Ltd. This software is licensed under the
GNU Affero General Public License version 3 (see the file LICENSE).
-->
@@ -9,34 +9,34 @@
xmlns:zope="http://namespaces.zope.org/zope"
i18n_domain="launchpad">
- <class class="canonical.launchpad.utilities.geoip.GeoIP">
- <allow interface="canonical.launchpad.interfaces.IGeoIP" />
+ <class class="lp.services.geoip.model.GeoIP">
+ <allow interface="lp.services.geoip.interfaces.IGeoIP" />
</class>
<securedutility
- class="canonical.launchpad.utilities.geoip.GeoIP"
- provides="canonical.launchpad.interfaces.IGeoIP">
- <allow interface="canonical.launchpad.interfaces.IGeoIP" />
+ class="lp.services.geoip.model.GeoIP"
+ provides="lp.services.geoip.interfaces.IGeoIP">
+ <allow interface="lp.services.geoip.interfaces.IGeoIP" />
</securedutility>
<adapter
for="zope.publisher.interfaces.browser.IBrowserRequest"
- factory="canonical.launchpad.utilities.geoip.RequestLocalLanguages"
- provides="canonical.launchpad.interfaces.IRequestLocalLanguages" />
-
- <adapter
- for="zope.publisher.interfaces.browser.IBrowserRequest"
- factory="canonical.launchpad.utilities.geoip.RequestPreferredLanguages"
- provides="canonical.launchpad.interfaces.IRequestPreferredLanguages" />
-
- <adapter
- for="zope.publisher.interfaces.browser.IBrowserRequest"
- factory="canonical.launchpad.components.request_country.request_country"
- provides="canonical.launchpad.interfaces.ICountry" />
-
- <adapter
- for="zope.publisher.interfaces.browser.IBrowserRequest"
- factory="canonical.launchpad.utilities.geoip.GeoIPRequest"
- provides="canonical.launchpad.interfaces.IGeoIPRecord" />
+ factory="lp.services.geoip.model.RequestLocalLanguages"
+ provides="lp.services.geoip.interfaces.IRequestLocalLanguages" />
+
+ <adapter
+ for="zope.publisher.interfaces.browser.IBrowserRequest"
+ factory="lp.services.geoip.model.RequestPreferredLanguages"
+ provides="lp.services.geoip.interfaces.IRequestPreferredLanguages" />
+
+ <adapter
+ for="zope.publisher.interfaces.browser.IBrowserRequest"
+ factory="lp.services.geoip.helpers.request_country"
+ provides="lp.services.worlddata.interfaces.country.ICountry" />
+
+ <adapter
+ for="zope.publisher.interfaces.browser.IBrowserRequest"
+ factory="lp.services.geoip.model.GeoIPRequest"
+ provides="lp.services.geoip.interfaces.IGeoIPRecord" />
</configure>
=== added directory 'lib/lp/services/geoip/doc'
=== renamed file 'lib/canonical/launchpad/doc/geoip.txt' => 'lib/lp/services/geoip/doc/geoip.txt'
--- lib/canonical/launchpad/doc/geoip.txt 2009-04-17 10:32:16 +0000
+++ lib/lp/services/geoip/doc/geoip.txt 2010-09-12 16:06:00 +0000
@@ -1,10 +1,11 @@
-= GeoIP =
+GeoIP
+=====
GeoIP allows us to guess the location of a user based on his IP address.
Our IGeoIP utility provides a couple methods to get location information
from a given IP address.
- >>> from canonical.launchpad.interfaces.geoip import IGeoIP
+ >>> from lp.services.geoip.interfaces import IGeoIP
>>> geoip = getUtility(IGeoIP)
The getCountryByAddr() method will return the country of the given IP
@@ -80,14 +81,13 @@
request's originating IP address.
>>> from canonical.launchpad.webapp.servers import LaunchpadTestRequest
- >>> from canonical.launchpad.interfaces.geoip import IGeoIPRecord
+ >>> from lp.services.geoip.interfaces import IGeoIPRecord
>>> request = LaunchpadTestRequest()
Since our request won't have an originating IP address, we'll use that
same South African IP address.
- >>> from canonical.launchpad.components.request_country import (
- ... ipaddress_from_request)
+ >>> from lp.services.geoip.helpers import ipaddress_from_request
>>> print ipaddress_from_request(request)
None
>>> geoip_request = IGeoIPRecord(request)
=== renamed file 'lib/canonical/launchpad/components/request_country.py' => 'lib/lp/services/geoip/helpers.py'
--- lib/canonical/launchpad/components/request_country.py 2010-08-20 20:31:18 +0000
+++ lib/lp/services/geoip/helpers.py 2010-09-12 16:06:00 +0000
@@ -7,10 +7,14 @@
from zope.component import getUtility
-from canonical.launchpad.interfaces import IGeoIP
-
-
-__all__ = ['request_country', 'ipaddress_from_request']
+from lp.services.geoip.interfaces import IGeoIP
+
+
+__all__ = [
+ 'request_country',
+ 'ipaddress_from_request',
+ ]
+
def request_country(request):
"""Adapt a request to the country in which the request was made.
@@ -26,8 +30,10 @@
return getUtility(IGeoIP).getCountryByAddr(ipaddress)
return None
+
_ipaddr_re = re.compile('\d\d?\d?\.\d\d?\d?\.\d\d?\d?\.\d\d?\d?')
+
def ipaddress_from_request(request):
"""Determine the IP address for this request.
@@ -67,8 +73,7 @@
ipaddresses = [
addr for addr in ipaddresses
if not (addr.startswith('127.')
- or _ipaddr_re.search(addr) is None)
- ]
+ or _ipaddr_re.search(addr) is None)]
if ipaddresses:
# If we have more than one, have a guess.
=== renamed file 'lib/canonical/launchpad/interfaces/geoip.py' => 'lib/lp/services/geoip/interfaces.py'
=== renamed file 'lib/canonical/launchpad/utilities/geoip.py' => 'lib/lp/services/geoip/model.py'
--- lib/canonical/launchpad/utilities/geoip.py 2010-08-24 10:45:57 +0000
+++ lib/lp/services/geoip/model.py 2010-09-12 16:06:00 +0000
@@ -16,10 +16,8 @@
from zope.interface import implements
from canonical.config import config
-from canonical.launchpad.components.request_country import (
- ipaddress_from_request,
- )
-from canonical.launchpad.interfaces.geoip import (
+from lp.services.geoip.helpers import ipaddress_from_request
+from lp.services.geoip.interfaces import (
IGeoIP,
IGeoIPRecord,
IRequestLocalLanguages,
=== added directory 'lib/lp/services/geoip/tests'
=== added file 'lib/lp/services/geoip/tests/__init__.py'
=== renamed file 'lib/canonical/launchpad/components/tests/test_request_country.py' => 'lib/lp/services/geoip/tests/test_doc.py'
--- lib/canonical/launchpad/components/tests/test_request_country.py 2010-08-20 20:31:18 +0000
+++ lib/lp/services/geoip/tests/test_doc.py 2010-09-12 16:06:00 +0000
@@ -1,19 +1,23 @@
-# Copyright 2009 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2010 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
-"""Module docstring goes here."""
+"""Test GEOIP documentation."""
__metaclass__ = type
+import os
from doctest import DocTestSuite
-import unittest
+
+from canonical.testing.layers import LaunchpadFunctionalLayer
+from lp.services.testing import build_test_suite
+
+
+here = os.path.dirname(os.path.realpath(__file__))
def test_suite():
- import canonical.launchpad.components.request_country
- return DocTestSuite(canonical.launchpad.components.request_country)
-
-if __name__ == '__main__':
- DEFAULT = test_suite()
- unittest.main(defaultTest='DEFAULT')
-
+ import lp.services.geoip.helpers
+ inline_doctest = DocTestSuite(lp.services.geoip.helpers)
+ suite = build_test_suite(here, {}, layer=LaunchpadFunctionalLayer)
+ suite.addTest(inline_doctest)
+ return suite
=== renamed file 'lib/canonical/launchpad/components/ftests/test_request_country.py' => 'lib/lp/services/geoip/tests/test_request_country.py'
--- lib/canonical/launchpad/components/ftests/test_request_country.py 2010-08-20 20:31:18 +0000
+++ lib/lp/services/geoip/tests/test_request_country.py 2010-09-12 16:06:00 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2010 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Functional tests for request_country"""
@@ -6,12 +6,12 @@
import unittest
-from canonical.launchpad.components.request_country import request_country
from canonical.launchpad.ftests import (
ANONYMOUS,
login,
logout,
)
+from lp.services.geoip.helpers import request_country
from canonical.testing import LaunchpadFunctionalLayer
=== modified file 'lib/lp/translations/browser/translations.py'
--- lib/lp/translations/browser/translations.py 2010-08-24 10:45:57 +0000
+++ lib/lp/translations/browser/translations.py 2010-09-12 16:06:00 +0000
@@ -19,7 +19,6 @@
from canonical.config import config
from canonical.launchpad import helpers
-from canonical.launchpad.interfaces.geoip import IRequestPreferredLanguages
from canonical.launchpad.interfaces.launchpad import (
ILaunchpadCelebrities,
IRosettaApplication,
@@ -35,6 +34,7 @@
from canonical.launchpad.webapp.interfaces import ILaunchpadRoot
from lp.registry.interfaces.person import IPersonSet
from lp.registry.interfaces.product import IProductSet
+from lp.services.geoip.interfaces import IRequestPreferredLanguages
from lp.services.propertycache import cachedproperty
from lp.services.worlddata.interfaces.country import ICountry
from lp.translations.publisher import TranslationsLayer
=== modified file 'lib/lp/translations/doc/preferred-languages.txt'
--- lib/lp/translations/doc/preferred-languages.txt 2009-10-22 11:55:51 +0000
+++ lib/lp/translations/doc/preferred-languages.txt 2010-09-12 16:06:00 +0000
@@ -3,8 +3,7 @@
in ASCII we just skip them.
>>> from canonical.launchpad.webapp.servers import LaunchpadTestRequest
- >>> from canonical.launchpad.utilities.geoip import (
- ... RequestPreferredLanguages)
+ >>> from lp.services.geoip.model import RequestPreferredLanguages
>>> langs = {'HTTP_ACCEPT_LANGUAGE': 'pt_BR, Espa\xf1ol'}
>>> request = LaunchpadTestRequest(**langs)