Merge lp:~maxiberta/launchpad/rename-google-as-sitesearch-extra into lp:launchpad

Proposed by Maximiliano Bertacchini
Status: Merged
Merged at revision: 18593
Proposed branch: lp:~maxiberta/launchpad/rename-google-as-sitesearch-extra
Merge into: lp:launchpad
Diff against target: 268 lines (+34/-33)
6 files modified
lib/lp/app/browser/root.py (+5/-5)
lib/lp/app/browser/tests/launchpad-search-pages.txt (+9/-9)
lib/lp/services/sitesearch/__init__.py (+5/-4)
lib/lp/services/sitesearch/doc/google-searchservice.txt (+1/-1)
lib/lp/services/sitesearch/interfaces.py (+3/-3)
lib/lp/services/sitesearch/tests/test_google.py (+11/-11)
To merge this branch: bzr merge lp:~maxiberta/launchpad/rename-google-as-sitesearch-extra
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+342148@code.launchpad.net

Commit message

A few extra renamed classes from Google* to SiteSearch*.

Description of the change

A few extra renamed classes from Google* to SiteSearch*.

- Rename GoogleBatchNavigator as SiteSearchBatchNavigator.
- Rename GoogleResponseError as SiteSearchResponseError.

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/app/browser/root.py'
--- lib/lp/app/browser/root.py 2018-03-16 14:50:01 +0000
+++ lib/lp/app/browser/root.py 2018-03-27 14:32:46 +0000
@@ -42,8 +42,8 @@
42from lp.services.memcache.interfaces import IMemcacheClient42from lp.services.memcache.interfaces import IMemcacheClient
43from lp.services.propertycache import cachedproperty43from lp.services.propertycache import cachedproperty
44from lp.services.sitesearch.interfaces import (44from lp.services.sitesearch.interfaces import (
45 GoogleResponseError,
46 ISearchService,45 ISearchService,
46 SiteSearchResponseError,
47 )47 )
48from lp.services.statistics.interfaces.statistic import ILaunchpadStatisticSet48from lp.services.statistics.interfaces.statistic import ILaunchpadStatisticSet
49from lp.services.timeout import urlfetch49from lp.services.timeout import urlfetch
@@ -520,14 +520,14 @@
520 try:520 try:
521 page_matches = google_search.search(521 page_matches = google_search.search(
522 terms=query_terms, start=start)522 terms=query_terms, start=start)
523 except GoogleResponseError:523 except SiteSearchResponseError:
524 # There was a connectivity or Google service issue that means524 # There was a connectivity or Google service issue that means
525 # there is no data available at this moment.525 # there is no data available at this moment.
526 self.has_page_service = False526 self.has_page_service = False
527 return None527 return None
528 if len(page_matches) == 0:528 if len(page_matches) == 0:
529 return None529 return None
530 navigator = GoogleBatchNavigator(530 navigator = SiteSearchBatchNavigator(
531 page_matches, self.request, start=start)531 page_matches, self.request, start=start)
532 navigator.setHeadings(*self.batch_heading)532 navigator.setHeadings(*self.batch_heading)
533 return navigator533 return navigator
@@ -589,7 +589,7 @@
589 return self.start + len(self.list._window)589 return self.start + len(self.list._window)
590590
591591
592class GoogleBatchNavigator(BatchNavigator):592class SiteSearchBatchNavigator(BatchNavigator):
593 """A batch navigator with a fixed size of 20 items per batch."""593 """A batch navigator with a fixed size of 20 items per batch."""
594594
595 _batch_factory = WindowedListBatch595 _batch_factory = WindowedListBatch
@@ -614,7 +614,7 @@
614 :param callback: Not used.614 :param callback: Not used.
615 """615 """
616 results = WindowedList(results, start, results.total)616 results = WindowedList(results, start, results.total)
617 super(GoogleBatchNavigator, self).__init__(results, request,617 super(SiteSearchBatchNavigator, self).__init__(results, request,
618 start=start, size=size, callback=callback,618 start=start, size=size, callback=callback,
619 transient_parameters=transient_parameters,619 transient_parameters=transient_parameters,
620 force_start=force_start, range_factory=range_factory)620 force_start=force_start, range_factory=range_factory)
621621
=== modified file 'lib/lp/app/browser/tests/launchpad-search-pages.txt'
--- lib/lp/app/browser/tests/launchpad-search-pages.txt 2018-03-16 14:02:16 +0000
+++ lib/lp/app/browser/tests/launchpad-search-pages.txt 2018-03-27 14:32:46 +0000
@@ -416,7 +416,7 @@
416 >>> search_view.has_matches416 >>> search_view.has_matches
417 True417 True
418 >>> search_view.pages418 >>> search_view.pages
419 <...GoogleBatchNavigator ...>419 <...SiteSearchBatchNavigator ...>
420420
421The GoogleSearchService may not be available due to connectivity problems.421The GoogleSearchService may not be available due to connectivity problems.
422The view's has_page_service attribute reports when the search was performed422The view's has_page_service attribute reports when the search was performed
@@ -444,7 +444,7 @@
444 >>> search_view.batch_heading444 >>> search_view.batch_heading
445 (u'other page matching "launchpad"', u'other pages matching "launchpad"')445 (u'other page matching "launchpad"', u'other pages matching "launchpad"')
446446
447The GoogleBatchNavigator behaves like most BatchNavigators, except that447The SiteSearchBatchNavigator behaves like most BatchNavigators, except that
448its batch size is always 20. The size restriction conforms to Google's448its batch size is always 20. The size restriction conforms to Google's
449maximum number of results that can be returned per request.449maximum number of results that can be returned per request.
450450
@@ -625,7 +625,7 @@
625 </div>625 </div>
626 </form>626 </form>
627627
628WindowedList and GoogleBatchNavigator628WindowedList and SiteSearchBatchNavigator
629-------------------------------------629-------------------------------------
630630
631The LaunchpadSearchView uses two helper classes to work with631The LaunchpadSearchView uses two helper classes to work with
@@ -635,7 +635,7 @@
635or fewer PageMatches of what could be thousands of matches. Google635or fewer PageMatches of what could be thousands of matches. Google
636requires client's to make repeats request to step though the batches of636requires client's to make repeats request to step though the batches of
637matches. The Windowed list is a list that contains only a subset of its637matches. The Windowed list is a list that contains only a subset of its
638reported size. It is used to make batches in the GoogleBatchNavigator.638reported size. It is used to make batches in the SiteSearchBatchNavigator.
639639
640For example, the last batch of the 'bug' search contained 5 of the 25640For example, the last batch of the 'bug' search contained 5 of the 25
641matching pages. The WindowList claims to be 25 items in length, but641matching pages. The WindowList claims to be 25 items in length, but
@@ -657,14 +657,14 @@
657 >>> results[18, 22]657 >>> results[18, 22]
658 [None, None, <...PageMatch ...>, <...PageMatch ...>]658 [None, None, <...PageMatch ...>, <...PageMatch ...>]
659659
660The GoogleBatchNavigator restricts the batch size to 20. the 'batch'660The SiteSearchBatchNavigator restricts the batch size to 20. the 'batch'
661parameter that comes from the URL is ignored. For example, setting661parameter that comes from the URL is ignored. For example, setting
662the 'batch' parameter to 100 has no affect upon the Google search662the 'batch' parameter to 100 has no affect upon the Google search
663or on the navigator object.663or on the navigator object.
664664
665 >>> from lp.app.browser.root import GoogleBatchNavigator665 >>> from lp.app.browser.root import SiteSearchBatchNavigator
666666
667 >>> GoogleBatchNavigator.batch_variable_name667 >>> SiteSearchBatchNavigator.batch_variable_name
668 'batch'668 'batch'
669669
670 >>> search_view = getSearchView(670 >>> search_view = getSearchView(
@@ -687,7 +687,7 @@
687 >>> page_matches._matches = matches687 >>> page_matches._matches = matches
688 >>> page_matches.start = 0688 >>> page_matches.start = 0
689 >>> page_matches.total = 100689 >>> page_matches.total = 100
690 >>> navigator = GoogleBatchNavigator(690 >>> navigator = SiteSearchBatchNavigator(
691 ... page_matches, search_view.request, page_matches.start, size=100)691 ... page_matches, search_view.request, page_matches.start, size=100)
692 >>> navigator.currentBatch().size692 >>> navigator.currentBatch().size
693 20693 20
@@ -705,7 +705,7 @@
705705
706 >>> matches = list(range(0, 3))706 >>> matches = list(range(0, 3))
707 >>> page_matches._matches = matches707 >>> page_matches._matches = matches
708 >>> navigator = GoogleBatchNavigator(708 >>> navigator = SiteSearchBatchNavigator(
709 ... page_matches, search_view.request, page_matches.start, size=100)709 ... page_matches, search_view.request, page_matches.start, size=100)
710 >>> batch = navigator.currentBatch()710 >>> batch = navigator.currentBatch()
711 >>> batch.size711 >>> batch.size
712712
=== modified file 'lib/lp/services/sitesearch/__init__.py'
--- lib/lp/services/sitesearch/__init__.py 2018-03-26 21:56:11 +0000
+++ lib/lp/services/sitesearch/__init__.py 2018-03-27 14:32:46 +0000
@@ -25,11 +25,11 @@
2525
26from lp.services.config import config26from lp.services.config import config
27from lp.services.sitesearch.interfaces import (27from lp.services.sitesearch.interfaces import (
28 GoogleResponseError,
29 GoogleWrongGSPVersion,28 GoogleWrongGSPVersion,
30 ISearchResult,29 ISearchResult,
31 ISearchResults,30 ISearchResults,
32 ISearchService,31 ISearchService,
32 SiteSearchResponseError,
33 )33 )
34from lp.services.timeline.requesttimeline import get_request_timeline34from lp.services.timeline.requesttimeline import get_request_timeline
35from lp.services.timeout import (35from lp.services.timeout import (
@@ -214,7 +214,7 @@
214 except (TimeoutError, requests.RequestException) as error:214 except (TimeoutError, requests.RequestException) as error:
215 # Google search service errors are not code errors. Let the215 # Google search service errors are not code errors. Let the
216 # call site choose to handle the unavailable service.216 # call site choose to handle the unavailable service.
217 raise GoogleResponseError(217 raise SiteSearchResponseError(
218 "The response errored: %s" % str(error))218 "The response errored: %s" % str(error))
219 finally:219 finally:
220 action.finish()220 action.finish()
@@ -276,7 +276,7 @@
276 version 3.2 XML. There is no guarantee that other GSP versions276 version 3.2 XML. There is no guarantee that other GSP versions
277 can be parsed.277 can be parsed.
278 :return: `ISearchResults` (PageMatches).278 :return: `ISearchResults` (PageMatches).
279 :raise: `GoogleResponseError` if the xml is incomplete.279 :raise: `SiteSearchResponseError` if the xml is incomplete.
280 :raise: `GoogleWrongGSPVersion` if the xml cannot be parsed.280 :raise: `GoogleWrongGSPVersion` if the xml cannot be parsed.
281 """281 """
282 try:282 try:
@@ -284,7 +284,8 @@
284 start_param = self._getElementByAttributeValue(284 start_param = self._getElementByAttributeValue(
285 gsp_doc, './PARAM', 'name', 'start')285 gsp_doc, './PARAM', 'name', 'start')
286 except (SyntaxError, IndexError):286 except (SyntaxError, IndexError):
287 raise GoogleResponseError("The response was incomplete, no xml.")287 raise SiteSearchResponseError(
288 "The response was incomplete, no xml.")
288 try:289 try:
289 start = int(start_param.get('value'))290 start = int(start_param.get('value'))
290 except (AttributeError, ValueError):291 except (AttributeError, ValueError):
291292
=== modified file 'lib/lp/services/sitesearch/doc/google-searchservice.txt'
--- lib/lp/services/sitesearch/doc/google-searchservice.txt 2018-03-26 20:41:30 +0000
+++ lib/lp/services/sitesearch/doc/google-searchservice.txt 2018-03-27 14:32:46 +0000
@@ -617,7 +617,7 @@
617 >>> google_search.search(terms='bug')617 >>> google_search.search(terms='bug')
618 Traceback (most recent call last):618 Traceback (most recent call last):
619 ...619 ...
620 GoogleResponseError: ... timeout exceeded.620 SiteSearchResponseError: ... timeout exceeded.
621621
622 # Restore the configuration and the timeout state.622 # Restore the configuration and the timeout state.
623 >>> timeout_data = config.pop('timeout_data')623 >>> timeout_data = config.pop('timeout_data')
624624
=== modified file 'lib/lp/services/sitesearch/interfaces.py'
--- lib/lp/services/sitesearch/interfaces.py 2013-01-07 02:40:55 +0000
+++ lib/lp/services/sitesearch/interfaces.py 2018-03-27 14:32:46 +0000
@@ -9,8 +9,8 @@
9 'ISearchResult',9 'ISearchResult',
10 'ISearchResults',10 'ISearchResults',
11 'ISearchService',11 'ISearchService',
12 'GoogleResponseError',
13 'GoogleWrongGSPVersion',12 'GoogleWrongGSPVersion',
13 'SiteSearchResponseError',
14 ]14 ]
1515
16from zope.interface import Interface16from zope.interface import Interface
@@ -74,8 +74,8 @@
74 """Raised when the content is not parsable Google Search Protocol XML."""74 """Raised when the content is not parsable Google Search Protocol XML."""
7575
7676
77class GoogleResponseError(SyntaxError):77class SiteSearchResponseError(ValueError):
78 """Raised when Google's response is not contain valid XML."""78 """Raised when the search engine's response cannot be parsed."""
7979
8080
81class ISearchService(Interface):81class ISearchService(Interface):
8282
=== modified file 'lib/lp/services/sitesearch/tests/test_google.py'
--- lib/lp/services/sitesearch/tests/test_google.py 2018-03-16 14:02:16 +0000
+++ lib/lp/services/sitesearch/tests/test_google.py 2018-03-27 14:32:46 +0000
@@ -13,7 +13,7 @@
13 )13 )
1414
15from lp.services.sitesearch import GoogleSearchService15from lp.services.sitesearch import GoogleSearchService
16from lp.services.sitesearch.interfaces import GoogleResponseError16from lp.services.sitesearch.interfaces import SiteSearchResponseError
17from lp.services.timeout import TimeoutError17from lp.services.timeout import TimeoutError
18from lp.testing import TestCase18from lp.testing import TestCase
19from lp.testing.layers import LaunchpadFunctionalLayer19from lp.testing.layers import LaunchpadFunctionalLayer
@@ -49,37 +49,37 @@
49 self.search_service = GoogleSearchService()49 self.search_service = GoogleSearchService()
5050
51 def test_search_converts_HTTPError(self):51 def test_search_converts_HTTPError(self):
52 # The method converts HTTPError to GoogleResponseError.52 # The method converts HTTPError to SiteSearchResponseError.
53 args = ('url', 500, 'oops', {}, None)53 args = ('url', 500, 'oops', {}, None)
54 with urlfetch_exception(HTTPError, *args):54 with urlfetch_exception(HTTPError, *args):
55 self.assertRaises(55 self.assertRaises(
56 GoogleResponseError, self.search_service.search, 'fnord')56 SiteSearchResponseError, self.search_service.search, 'fnord')
5757
58 def test_search_converts_ConnectionError(self):58 def test_search_converts_ConnectionError(self):
59 # The method converts ConnectionError to GoogleResponseError.59 # The method converts ConnectionError to SiteSearchResponseError.
60 with urlfetch_exception(ConnectionError, 'oops'):60 with urlfetch_exception(ConnectionError, 'oops'):
61 self.assertRaises(61 self.assertRaises(
62 GoogleResponseError, self.search_service.search, 'fnord')62 SiteSearchResponseError, self.search_service.search, 'fnord')
6363
64 def test_search_converts_TimeoutError(self):64 def test_search_converts_TimeoutError(self):
65 # The method converts TimeoutError to GoogleResponseError.65 # The method converts TimeoutError to SiteSearchResponseError.
66 with urlfetch_exception(TimeoutError, 'oops'):66 with urlfetch_exception(TimeoutError, 'oops'):
67 self.assertRaises(67 self.assertRaises(
68 GoogleResponseError, self.search_service.search, 'fnord')68 SiteSearchResponseError, self.search_service.search, 'fnord')
6969
70 def test___parse_google_search_protocol_SyntaxError(self):70 def test___parse_google_search_protocol_SyntaxError(self):
71 # The method converts SyntaxError to GoogleResponseError.71 # The method converts SyntaxError to SiteSearchResponseError.
72 with urlfetch_exception(SyntaxError, 'oops'):72 with urlfetch_exception(SyntaxError, 'oops'):
73 self.assertRaises(73 self.assertRaises(
74 GoogleResponseError,74 SiteSearchResponseError,
75 self.search_service._parse_google_search_protocol, '')75 self.search_service._parse_google_search_protocol, '')
7676
77 def test___parse_google_search_protocol_IndexError(self):77 def test___parse_google_search_protocol_IndexError(self):
78 # The method converts IndexError to GoogleResponseError.78 # The method converts IndexError to SiteSearchResponseError.
79 with urlfetch_exception(IndexError, 'oops'):79 with urlfetch_exception(IndexError, 'oops'):
80 data = (80 data = (
81 '<?xml version="1.0" encoding="UTF-8" standalone="no"?>'81 '<?xml version="1.0" encoding="UTF-8" standalone="no"?>'
82 '<GSP VER="3.2"></GSP>')82 '<GSP VER="3.2"></GSP>')
83 self.assertRaises(83 self.assertRaises(
84 GoogleResponseError,84 SiteSearchResponseError,
85 self.search_service._parse_google_search_protocol, data)85 self.search_service._parse_google_search_protocol, data)