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
1=== modified file 'lib/lp/app/browser/root.py'
2--- lib/lp/app/browser/root.py 2018-03-16 14:50:01 +0000
3+++ lib/lp/app/browser/root.py 2018-03-27 14:32:46 +0000
4@@ -42,8 +42,8 @@
5 from lp.services.memcache.interfaces import IMemcacheClient
6 from lp.services.propertycache import cachedproperty
7 from lp.services.sitesearch.interfaces import (
8- GoogleResponseError,
9 ISearchService,
10+ SiteSearchResponseError,
11 )
12 from lp.services.statistics.interfaces.statistic import ILaunchpadStatisticSet
13 from lp.services.timeout import urlfetch
14@@ -520,14 +520,14 @@
15 try:
16 page_matches = google_search.search(
17 terms=query_terms, start=start)
18- except GoogleResponseError:
19+ except SiteSearchResponseError:
20 # There was a connectivity or Google service issue that means
21 # there is no data available at this moment.
22 self.has_page_service = False
23 return None
24 if len(page_matches) == 0:
25 return None
26- navigator = GoogleBatchNavigator(
27+ navigator = SiteSearchBatchNavigator(
28 page_matches, self.request, start=start)
29 navigator.setHeadings(*self.batch_heading)
30 return navigator
31@@ -589,7 +589,7 @@
32 return self.start + len(self.list._window)
33
34
35-class GoogleBatchNavigator(BatchNavigator):
36+class SiteSearchBatchNavigator(BatchNavigator):
37 """A batch navigator with a fixed size of 20 items per batch."""
38
39 _batch_factory = WindowedListBatch
40@@ -614,7 +614,7 @@
41 :param callback: Not used.
42 """
43 results = WindowedList(results, start, results.total)
44- super(GoogleBatchNavigator, self).__init__(results, request,
45+ super(SiteSearchBatchNavigator, self).__init__(results, request,
46 start=start, size=size, callback=callback,
47 transient_parameters=transient_parameters,
48 force_start=force_start, range_factory=range_factory)
49
50=== modified file 'lib/lp/app/browser/tests/launchpad-search-pages.txt'
51--- lib/lp/app/browser/tests/launchpad-search-pages.txt 2018-03-16 14:02:16 +0000
52+++ lib/lp/app/browser/tests/launchpad-search-pages.txt 2018-03-27 14:32:46 +0000
53@@ -416,7 +416,7 @@
54 >>> search_view.has_matches
55 True
56 >>> search_view.pages
57- <...GoogleBatchNavigator ...>
58+ <...SiteSearchBatchNavigator ...>
59
60 The GoogleSearchService may not be available due to connectivity problems.
61 The view's has_page_service attribute reports when the search was performed
62@@ -444,7 +444,7 @@
63 >>> search_view.batch_heading
64 (u'other page matching "launchpad"', u'other pages matching "launchpad"')
65
66-The GoogleBatchNavigator behaves like most BatchNavigators, except that
67+The SiteSearchBatchNavigator behaves like most BatchNavigators, except that
68 its batch size is always 20. The size restriction conforms to Google's
69 maximum number of results that can be returned per request.
70
71@@ -625,7 +625,7 @@
72 </div>
73 </form>
74
75-WindowedList and GoogleBatchNavigator
76+WindowedList and SiteSearchBatchNavigator
77 -------------------------------------
78
79 The LaunchpadSearchView uses two helper classes to work with
80@@ -635,7 +635,7 @@
81 or fewer PageMatches of what could be thousands of matches. Google
82 requires client's to make repeats request to step though the batches of
83 matches. The Windowed list is a list that contains only a subset of its
84-reported size. It is used to make batches in the GoogleBatchNavigator.
85+reported size. It is used to make batches in the SiteSearchBatchNavigator.
86
87 For example, the last batch of the 'bug' search contained 5 of the 25
88 matching pages. The WindowList claims to be 25 items in length, but
89@@ -657,14 +657,14 @@
90 >>> results[18, 22]
91 [None, None, <...PageMatch ...>, <...PageMatch ...>]
92
93-The GoogleBatchNavigator restricts the batch size to 20. the 'batch'
94+The SiteSearchBatchNavigator restricts the batch size to 20. the 'batch'
95 parameter that comes from the URL is ignored. For example, setting
96 the 'batch' parameter to 100 has no affect upon the Google search
97 or on the navigator object.
98
99- >>> from lp.app.browser.root import GoogleBatchNavigator
100+ >>> from lp.app.browser.root import SiteSearchBatchNavigator
101
102- >>> GoogleBatchNavigator.batch_variable_name
103+ >>> SiteSearchBatchNavigator.batch_variable_name
104 'batch'
105
106 >>> search_view = getSearchView(
107@@ -687,7 +687,7 @@
108 >>> page_matches._matches = matches
109 >>> page_matches.start = 0
110 >>> page_matches.total = 100
111- >>> navigator = GoogleBatchNavigator(
112+ >>> navigator = SiteSearchBatchNavigator(
113 ... page_matches, search_view.request, page_matches.start, size=100)
114 >>> navigator.currentBatch().size
115 20
116@@ -705,7 +705,7 @@
117
118 >>> matches = list(range(0, 3))
119 >>> page_matches._matches = matches
120- >>> navigator = GoogleBatchNavigator(
121+ >>> navigator = SiteSearchBatchNavigator(
122 ... page_matches, search_view.request, page_matches.start, size=100)
123 >>> batch = navigator.currentBatch()
124 >>> batch.size
125
126=== modified file 'lib/lp/services/sitesearch/__init__.py'
127--- lib/lp/services/sitesearch/__init__.py 2018-03-26 21:56:11 +0000
128+++ lib/lp/services/sitesearch/__init__.py 2018-03-27 14:32:46 +0000
129@@ -25,11 +25,11 @@
130
131 from lp.services.config import config
132 from lp.services.sitesearch.interfaces import (
133- GoogleResponseError,
134 GoogleWrongGSPVersion,
135 ISearchResult,
136 ISearchResults,
137 ISearchService,
138+ SiteSearchResponseError,
139 )
140 from lp.services.timeline.requesttimeline import get_request_timeline
141 from lp.services.timeout import (
142@@ -214,7 +214,7 @@
143 except (TimeoutError, requests.RequestException) as error:
144 # Google search service errors are not code errors. Let the
145 # call site choose to handle the unavailable service.
146- raise GoogleResponseError(
147+ raise SiteSearchResponseError(
148 "The response errored: %s" % str(error))
149 finally:
150 action.finish()
151@@ -276,7 +276,7 @@
152 version 3.2 XML. There is no guarantee that other GSP versions
153 can be parsed.
154 :return: `ISearchResults` (PageMatches).
155- :raise: `GoogleResponseError` if the xml is incomplete.
156+ :raise: `SiteSearchResponseError` if the xml is incomplete.
157 :raise: `GoogleWrongGSPVersion` if the xml cannot be parsed.
158 """
159 try:
160@@ -284,7 +284,8 @@
161 start_param = self._getElementByAttributeValue(
162 gsp_doc, './PARAM', 'name', 'start')
163 except (SyntaxError, IndexError):
164- raise GoogleResponseError("The response was incomplete, no xml.")
165+ raise SiteSearchResponseError(
166+ "The response was incomplete, no xml.")
167 try:
168 start = int(start_param.get('value'))
169 except (AttributeError, ValueError):
170
171=== modified file 'lib/lp/services/sitesearch/doc/google-searchservice.txt'
172--- lib/lp/services/sitesearch/doc/google-searchservice.txt 2018-03-26 20:41:30 +0000
173+++ lib/lp/services/sitesearch/doc/google-searchservice.txt 2018-03-27 14:32:46 +0000
174@@ -617,7 +617,7 @@
175 >>> google_search.search(terms='bug')
176 Traceback (most recent call last):
177 ...
178- GoogleResponseError: ... timeout exceeded.
179+ SiteSearchResponseError: ... timeout exceeded.
180
181 # Restore the configuration and the timeout state.
182 >>> timeout_data = config.pop('timeout_data')
183
184=== modified file 'lib/lp/services/sitesearch/interfaces.py'
185--- lib/lp/services/sitesearch/interfaces.py 2013-01-07 02:40:55 +0000
186+++ lib/lp/services/sitesearch/interfaces.py 2018-03-27 14:32:46 +0000
187@@ -9,8 +9,8 @@
188 'ISearchResult',
189 'ISearchResults',
190 'ISearchService',
191- 'GoogleResponseError',
192 'GoogleWrongGSPVersion',
193+ 'SiteSearchResponseError',
194 ]
195
196 from zope.interface import Interface
197@@ -74,8 +74,8 @@
198 """Raised when the content is not parsable Google Search Protocol XML."""
199
200
201-class GoogleResponseError(SyntaxError):
202- """Raised when Google's response is not contain valid XML."""
203+class SiteSearchResponseError(ValueError):
204+ """Raised when the search engine's response cannot be parsed."""
205
206
207 class ISearchService(Interface):
208
209=== modified file 'lib/lp/services/sitesearch/tests/test_google.py'
210--- lib/lp/services/sitesearch/tests/test_google.py 2018-03-16 14:02:16 +0000
211+++ lib/lp/services/sitesearch/tests/test_google.py 2018-03-27 14:32:46 +0000
212@@ -13,7 +13,7 @@
213 )
214
215 from lp.services.sitesearch import GoogleSearchService
216-from lp.services.sitesearch.interfaces import GoogleResponseError
217+from lp.services.sitesearch.interfaces import SiteSearchResponseError
218 from lp.services.timeout import TimeoutError
219 from lp.testing import TestCase
220 from lp.testing.layers import LaunchpadFunctionalLayer
221@@ -49,37 +49,37 @@
222 self.search_service = GoogleSearchService()
223
224 def test_search_converts_HTTPError(self):
225- # The method converts HTTPError to GoogleResponseError.
226+ # The method converts HTTPError to SiteSearchResponseError.
227 args = ('url', 500, 'oops', {}, None)
228 with urlfetch_exception(HTTPError, *args):
229 self.assertRaises(
230- GoogleResponseError, self.search_service.search, 'fnord')
231+ SiteSearchResponseError, self.search_service.search, 'fnord')
232
233 def test_search_converts_ConnectionError(self):
234- # The method converts ConnectionError to GoogleResponseError.
235+ # The method converts ConnectionError to SiteSearchResponseError.
236 with urlfetch_exception(ConnectionError, 'oops'):
237 self.assertRaises(
238- GoogleResponseError, self.search_service.search, 'fnord')
239+ SiteSearchResponseError, self.search_service.search, 'fnord')
240
241 def test_search_converts_TimeoutError(self):
242- # The method converts TimeoutError to GoogleResponseError.
243+ # The method converts TimeoutError to SiteSearchResponseError.
244 with urlfetch_exception(TimeoutError, 'oops'):
245 self.assertRaises(
246- GoogleResponseError, self.search_service.search, 'fnord')
247+ SiteSearchResponseError, self.search_service.search, 'fnord')
248
249 def test___parse_google_search_protocol_SyntaxError(self):
250- # The method converts SyntaxError to GoogleResponseError.
251+ # The method converts SyntaxError to SiteSearchResponseError.
252 with urlfetch_exception(SyntaxError, 'oops'):
253 self.assertRaises(
254- GoogleResponseError,
255+ SiteSearchResponseError,
256 self.search_service._parse_google_search_protocol, '')
257
258 def test___parse_google_search_protocol_IndexError(self):
259- # The method converts IndexError to GoogleResponseError.
260+ # The method converts IndexError to SiteSearchResponseError.
261 with urlfetch_exception(IndexError, 'oops'):
262 data = (
263 '<?xml version="1.0" encoding="UTF-8" standalone="no"?>'
264 '<GSP VER="3.2"></GSP>')
265 self.assertRaises(
266- GoogleResponseError,
267+ SiteSearchResponseError,
268 self.search_service._parse_google_search_protocol, data)