Browse Source

[fix] pep8 part II.

Adam Tauber 10 years ago
parent
commit
5740cfbf1c
6 changed files with 121 additions and 80 deletions
  1. 2
    1
      searx/__init__.py
  2. 6
    5
      searx/engines/__init__.py
  3. 23
    20
      searx/query.py
  4. 67
    37
      searx/search.py
  5. 5
    4
      searx/utils.py
  6. 18
    13
      searx/webapp.py

+ 2
- 1
searx/__init__.py View File

28
 searx_dir = abspath(dirname(__file__))
28
 searx_dir = abspath(dirname(__file__))
29
 engine_dir = dirname(realpath(__file__))
29
 engine_dir = dirname(realpath(__file__))
30
 
30
 
31
-# if possible set path to settings using the enviroment variable SEARX_SETTINGS_PATH
31
+# if possible set path to settings using the
32
+# enviroment variable SEARX_SETTINGS_PATH
32
 if 'SEARX_SETTINGS_PATH' in environ:
33
 if 'SEARX_SETTINGS_PATH' in environ:
33
     settings_path = environ['SEARX_SETTINGS_PATH']
34
     settings_path = environ['SEARX_SETTINGS_PATH']
34
 # otherwise using default path
35
 # otherwise using default path

+ 6
- 5
searx/engines/__init__.py View File

41
     module.name = modname
41
     module.name = modname
42
     return module
42
     return module
43
 
43
 
44
-if not 'engines' in settings or not settings['engines']:
44
+if 'engines' not in settings or not settings['engines']:
45
     print '[E] Error no engines found. Edit your settings.yml'
45
     print '[E] Error no engines found. Edit your settings.yml'
46
     exit(2)
46
     exit(2)
47
 
47
 
68
         engine.categories = ['general']
68
         engine.categories = ['general']
69
 
69
 
70
     if not hasattr(engine, 'language_support'):
70
     if not hasattr(engine, 'language_support'):
71
-        #engine.language_support = False
71
+        # engine.language_support = False
72
         engine.language_support = True
72
         engine.language_support = True
73
 
73
 
74
     if not hasattr(engine, 'timeout'):
74
     if not hasattr(engine, 'timeout'):
75
-        #engine.language_support = False
75
+        # engine.language_support = False
76
         engine.timeout = settings['server']['request_timeout']
76
         engine.timeout = settings['server']['request_timeout']
77
 
77
 
78
     if not hasattr(engine, 'shortcut'):
78
     if not hasattr(engine, 'shortcut'):
79
-        #engine.shortcut = '''
79
+        # engine.shortcut = '''
80
         engine.shortcut = ''
80
         engine.shortcut = ''
81
 
81
 
82
     # checking required variables
82
     # checking required variables
161
 
161
 
162
     for engine in scores_per_result:
162
     for engine in scores_per_result:
163
         if max_score_per_result:
163
         if max_score_per_result:
164
-            engine['percentage'] = int(engine['avg'] / max_score_per_result * 100)
164
+            engine['percentage'] = int(engine['avg']
165
+                                       / max_score_per_result * 100)
165
         else:
166
         else:
166
             engine['percentage'] = 0
167
             engine['percentage'] = 0
167
 
168
 

+ 23
- 20
searx/query.py View File

31
     def __init__(self, query, blocked_engines):
31
     def __init__(self, query, blocked_engines):
32
         self.query = query
32
         self.query = query
33
         self.blocked_engines = []
33
         self.blocked_engines = []
34
-        
34
+
35
         if blocked_engines:
35
         if blocked_engines:
36
             self.blocked_engines = blocked_engines
36
             self.blocked_engines = blocked_engines
37
-            
37
+
38
         self.query_parts = []
38
         self.query_parts = []
39
         self.engines = []
39
         self.engines = []
40
         self.languages = []
40
         self.languages = []
41
-    
42
-    # parse query, if tags are set, which change the serch engine or search-language
41
+
42
+    # parse query, if tags are set, which
43
+    # change the serch engine or search-language
43
     def parse_query(self):
44
     def parse_query(self):
44
         self.query_parts = []
45
         self.query_parts = []
45
-        
46
+
46
         # split query, including whitespaces
47
         # split query, including whitespaces
47
         raw_query_parts = re.split(r'(\s+)', self.query)
48
         raw_query_parts = re.split(r'(\s+)', self.query)
48
-        
49
+
49
         parse_next = True
50
         parse_next = True
50
-        
51
+
51
         for query_part in raw_query_parts:
52
         for query_part in raw_query_parts:
52
             if not parse_next:
53
             if not parse_next:
53
                 self.query_parts[-1] += query_part
54
                 self.query_parts[-1] += query_part
54
                 continue
55
                 continue
55
-           
56
+
56
             parse_next = False
57
             parse_next = False
57
-           
58
+
58
             # part does only contain spaces, skip
59
             # part does only contain spaces, skip
59
             if query_part.isspace()\
60
             if query_part.isspace()\
60
                or query_part == '':
61
                or query_part == '':
62
                 self.query_parts.append(query_part)
63
                 self.query_parts.append(query_part)
63
                 continue
64
                 continue
64
 
65
 
65
-            # this force a language            
66
+            # this force a language
66
             if query_part[0] == ':':
67
             if query_part[0] == ':':
67
                 lang = query_part[1:].lower()
68
                 lang = query_part[1:].lower()
68
 
69
 
69
-                # check if any language-code is equal with declared language-codes
70
+                # check if any language-code is equal with
71
+                # declared language-codes
70
                 for lc in language_codes:
72
                 for lc in language_codes:
71
                     lang_id, lang_name, country = map(str.lower, lc)
73
                     lang_id, lang_name, country = map(str.lower, lc)
72
 
74
 
73
-                    # if correct language-code is found, set it as new search-language
75
+                    # if correct language-code is found
76
+                    # set it as new search-language
74
                     if lang == lang_id\
77
                     if lang == lang_id\
75
                        or lang_id.startswith(lang)\
78
                        or lang_id.startswith(lang)\
76
                        or lang == lang_name\
79
                        or lang == lang_name\
89
                     parse_next = True
92
                     parse_next = True
90
                     self.engines.append({'category': 'none',
93
                     self.engines.append({'category': 'none',
91
                                          'name': engine_shortcuts[prefix]})
94
                                          'name': engine_shortcuts[prefix]})
92
-                
95
+
93
                 # check if prefix is equal with engine name
96
                 # check if prefix is equal with engine name
94
                 elif prefix in engines\
97
                 elif prefix in engines\
95
-                        and not prefix in self.blocked_engines:
98
+                        and prefix not in self.blocked_engines:
96
                     parse_next = True
99
                     parse_next = True
97
                     self.engines.append({'category': 'none',
100
                     self.engines.append({'category': 'none',
98
                                         'name': prefix})
101
                                         'name': prefix})
99
 
102
 
100
                 # check if prefix is equal with categorie name
103
                 # check if prefix is equal with categorie name
101
                 elif prefix in categories:
104
                 elif prefix in categories:
102
-                    # using all engines for that search, which are declared under that categorie name
105
+                    # using all engines for that search, which
106
+                    # are declared under that categorie name
103
                     parse_next = True
107
                     parse_next = True
104
                     self.engines.extend({'category': prefix,
108
                     self.engines.extend({'category': prefix,
105
                                         'name': engine.name}
109
                                         'name': engine.name}
106
                                         for engine in categories[prefix]
110
                                         for engine in categories[prefix]
107
-                                        if not engine in self.blocked_engines)
108
-          
111
+                                        if engine not in self.blocked_engines)
112
+
109
             # append query part to query_part list
113
             # append query part to query_part list
110
             self.query_parts.append(query_part)
114
             self.query_parts.append(query_part)
111
 
115
 
114
             self.query_parts[-1] = search_query
118
             self.query_parts[-1] = search_query
115
         else:
119
         else:
116
             self.query_parts.append(search_query)
120
             self.query_parts.append(search_query)
117
-            
121
+
118
     def getSearchQuery(self):
122
     def getSearchQuery(self):
119
         if len(self.query_parts):
123
         if len(self.query_parts):
120
             return self.query_parts[-1]
124
             return self.query_parts[-1]
121
         else:
125
         else:
122
             return ''
126
             return ''
123
-    
127
+
124
     def getFullQuery(self):
128
     def getFullQuery(self):
125
         # get full querry including whitespaces
129
         # get full querry including whitespaces
126
         return string.join(self.query_parts, '')
130
         return string.join(self.query_parts, '')
127
-

+ 67
- 37
searx/search.py View File

22
 from operator import itemgetter
22
 from operator import itemgetter
23
 from urlparse import urlparse, unquote
23
 from urlparse import urlparse, unquote
24
 from searx.engines import (
24
 from searx.engines import (
25
-    categories, engines, engine_shortcuts
25
+    categories, engines
26
 )
26
 )
27
 from searx.languages import language_codes
27
 from searx.languages import language_codes
28
 from searx.utils import gen_useragent
28
 from searx.utils import gen_useragent
39
 
39
 
40
 
40
 
41
 # create a callback wrapper for the search engine results
41
 # create a callback wrapper for the search engine results
42
-def make_callback(engine_name, results, suggestions, answers, infoboxes, callback, params):
42
+def make_callback(engine_name,
43
+                  results,
44
+                  suggestions,
45
+                  answers,
46
+                  infoboxes,
47
+                  callback,
48
+                  params):
43
 
49
 
44
     # creating a callback wrapper for the search engine results
50
     # creating a callback wrapper for the search engine results
45
     def process_callback(response, **kwargs):
51
     def process_callback(response, **kwargs):
95
 def content_result_len(content):
101
 def content_result_len(content):
96
     if isinstance(content, basestring):
102
     if isinstance(content, basestring):
97
         content = re.sub('[,;:!?\./\\\\ ()-_]', '', content)
103
         content = re.sub('[,;:!?\./\\\\ ()-_]', '', content)
98
-        return len(content) 
104
+        return len(content)
99
     else:
105
     else:
100
         return 0
106
         return 0
101
 
107
 
126
 
132
 
127
         # strip multiple spaces and cariage returns from content
133
         # strip multiple spaces and cariage returns from content
128
         if 'content' in res:
134
         if 'content' in res:
129
-            res['content'] = re.sub(' +', ' ', res['content'].strip().replace('\n', ''))
135
+            res['content'] = re.sub(' +', ' ',
136
+                                    res['content'].strip().replace('\n', ''))
130
 
137
 
131
         # get weight of this engine if possible
138
         # get weight of this engine if possible
132
         if hasattr(engines[res['engine']], 'weight'):
139
         if hasattr(engines[res['engine']], 'weight'):
139
         duplicated = False
146
         duplicated = False
140
         for new_res in results:
147
         for new_res in results:
141
             # remove / from the end of the url if required
148
             # remove / from the end of the url if required
142
-            p1 = res['parsed_url'].path[:-1] if res['parsed_url'].path.endswith('/') else res['parsed_url'].path  # noqa
143
-            p2 = new_res['parsed_url'].path[:-1] if new_res['parsed_url'].path.endswith('/') else new_res['parsed_url'].path  # noqa
149
+            p1 = res['parsed_url'].path[:-1]\
150
+                if res['parsed_url'].path.endswith('/')\
151
+                else res['parsed_url'].path
152
+            p2 = new_res['parsed_url'].path[:-1]\
153
+                if new_res['parsed_url'].path.endswith('/')\
154
+                else new_res['parsed_url'].path
144
 
155
 
145
             # check if that result is a duplicate
156
             # check if that result is a duplicate
146
             if res['host'] == new_res['host'] and\
157
             if res['host'] == new_res['host'] and\
153
         # merge duplicates together
164
         # merge duplicates together
154
         if duplicated:
165
         if duplicated:
155
             # using content with more text
166
             # using content with more text
156
-            if content_result_len(res.get('content', '')) > content_result_len(duplicated.get('content', '')):
167
+            if content_result_len(res.get('content', '')) >\
168
+                    content_result_len(duplicated.get('content', '')):
157
                 duplicated['content'] = res['content']
169
                 duplicated['content'] = res['content']
158
 
170
 
159
             # increase result-score
171
             # increase result-score
182
 
194
 
183
     for i, res in enumerate(results):
195
     for i, res in enumerate(results):
184
         # FIXME : handle more than one category per engine
196
         # FIXME : handle more than one category per engine
185
-        category = engines[res['engine']].categories[0] + ':' + '' if 'template' not in res else res['template']
186
-
187
-        current = None if category not in categoryPositions else categoryPositions[category]
188
-
189
-        # group with previous results using the same category if the group can accept more result and is not too far from the current position
190
-        if current != None and (current['count'] > 0) and (len(gresults) - current['index'] < 20):
191
-            # group with the previous results using the same category with this one
197
+        category = engines[res['engine']].categories[0] + ':' + ''\
198
+            if 'template' not in res\
199
+            else res['template']
200
+
201
+        current = None if category not in categoryPositions\
202
+            else categoryPositions[category]
203
+
204
+        # group with previous results using the same category
205
+        # if the group can accept more result and is not too far
206
+        # from the current position
207
+        if current is not None and (current['count'] > 0)\
208
+                and (len(gresults) - current['index'] < 20):
209
+            # group with the previous results using
210
+            # the same category with this one
192
             index = current['index']
211
             index = current['index']
193
             gresults.insert(index, res)
212
             gresults.insert(index, res)
194
 
213
 
195
-            # update every index after the current one (including the current one)
214
+            # update every index after the current one
215
+            # (including the current one)
196
             for k in categoryPositions:
216
             for k in categoryPositions:
197
                 v = categoryPositions[k]['index']
217
                 v = categoryPositions[k]['index']
198
                 if v >= index:
218
                 if v >= index:
206
             gresults.append(res)
226
             gresults.append(res)
207
 
227
 
208
             # update categoryIndex
228
             # update categoryIndex
209
-            categoryPositions[category] = { 'index' : len(gresults), 'count' : 8 }
229
+            categoryPositions[category] = {'index': len(gresults), 'count': 8}
210
 
230
 
211
     # return gresults
231
     # return gresults
212
     return gresults
232
     return gresults
215
 def merge_two_infoboxes(infobox1, infobox2):
235
 def merge_two_infoboxes(infobox1, infobox2):
216
     if 'urls' in infobox2:
236
     if 'urls' in infobox2:
217
         urls1 = infobox1.get('urls', None)
237
         urls1 = infobox1.get('urls', None)
218
-        if urls1 == None:
238
+        if urls1 is None:
219
             urls1 = []
239
             urls1 = []
220
             infobox1.set('urls', urls1)
240
             infobox1.set('urls', urls1)
221
 
241
 
222
         urlSet = set()
242
         urlSet = set()
223
         for url in infobox1.get('urls', []):
243
         for url in infobox1.get('urls', []):
224
             urlSet.add(url.get('url', None))
244
             urlSet.add(url.get('url', None))
225
-        
245
+
226
         for url in infobox2.get('urls', []):
246
         for url in infobox2.get('urls', []):
227
             if url.get('url', None) not in urlSet:
247
             if url.get('url', None) not in urlSet:
228
                 urls1.append(url)
248
                 urls1.append(url)
229
 
249
 
230
     if 'attributes' in infobox2:
250
     if 'attributes' in infobox2:
231
         attributes1 = infobox1.get('attributes', None)
251
         attributes1 = infobox1.get('attributes', None)
232
-        if attributes1 == None:
252
+        if attributes1 is None:
233
             attributes1 = []
253
             attributes1 = []
234
             infobox1.set('attributes', attributes1)
254
             infobox1.set('attributes', attributes1)
235
 
255
 
237
         for attribute in infobox1.get('attributes', []):
257
         for attribute in infobox1.get('attributes', []):
238
             if attribute.get('label', None) not in attributeSet:
258
             if attribute.get('label', None) not in attributeSet:
239
                 attributeSet.add(attribute.get('label', None))
259
                 attributeSet.add(attribute.get('label', None))
240
-        
260
+
241
         for attribute in infobox2.get('attributes', []):
261
         for attribute in infobox2.get('attributes', []):
242
             attributes1.append(attribute)
262
             attributes1.append(attribute)
243
 
263
 
244
     if 'content' in infobox2:
264
     if 'content' in infobox2:
245
         content1 = infobox1.get('content', None)
265
         content1 = infobox1.get('content', None)
246
         content2 = infobox2.get('content', '')
266
         content2 = infobox2.get('content', '')
247
-        if content1 != None:
267
+        if content1 is not None:
248
             if content_result_len(content2) > content_result_len(content1):
268
             if content_result_len(content2) > content_result_len(content1):
249
                 infobox1['content'] = content2
269
                 infobox1['content'] = content2
250
         else:
270
         else:
257
     for infobox in infoboxes:
277
     for infobox in infoboxes:
258
         add_infobox = True
278
         add_infobox = True
259
         infobox_id = infobox.get('id', None)
279
         infobox_id = infobox.get('id', None)
260
-        if infobox_id != None:
280
+        if infobox_id is not None:
261
             existingIndex = infoboxes_id.get(infobox_id, None)
281
             existingIndex = infoboxes_id.get(infobox_id, None)
262
-            if existingIndex != None:
282
+            if existingIndex is not None:
263
                 merge_two_infoboxes(results[existingIndex], infobox)
283
                 merge_two_infoboxes(results[existingIndex], infobox)
264
-                add_infobox=False
265
-            
284
+                add_infobox = False
285
+
266
         if add_infobox:
286
         if add_infobox:
267
             results.append(infobox)
287
             results.append(infobox)
268
             infoboxes_id[infobox_id] = len(results)-1
288
             infoboxes_id[infobox_id] = len(results)-1
318
 
338
 
319
         self.pageno = int(pageno_param)
339
         self.pageno = int(pageno_param)
320
 
340
 
321
-        # parse query, if tags are set, which change the serch engine or search-language
341
+        # parse query, if tags are set, which change
342
+        # the serch engine or search-language
322
         query_obj = Query(self.request_data['q'], self.blocked_engines)
343
         query_obj = Query(self.request_data['q'], self.blocked_engines)
323
         query_obj.parse_query()
344
         query_obj.parse_query()
324
 
345
 
334
 
355
 
335
         self.categories = []
356
         self.categories = []
336
 
357
 
337
-        # if engines are calculated from query, set categories by using that informations
358
+        # if engines are calculated from query,
359
+        # set categories by using that informations
338
         if self.engines:
360
         if self.engines:
339
             self.categories = list(set(engine['category']
361
             self.categories = list(set(engine['category']
340
                                        for engine in self.engines))
362
                                        for engine in self.engines))
341
 
363
 
342
-        # otherwise, using defined categories to calculate which engines should be used
364
+        # otherwise, using defined categories to
365
+        # calculate which engines should be used
343
         else:
366
         else:
344
             # set used categories
367
             # set used categories
345
             for pd_name, pd in self.request_data.items():
368
             for pd_name, pd in self.request_data.items():
346
                 if pd_name.startswith('category_'):
369
                 if pd_name.startswith('category_'):
347
                     category = pd_name[9:]
370
                     category = pd_name[9:]
348
                     # if category is not found in list, skip
371
                     # if category is not found in list, skip
349
-                    if not category in categories:
372
+                    if category not in categories:
350
                         continue
373
                         continue
351
 
374
 
352
                     # add category to list
375
                     # add category to list
353
                     self.categories.append(category)
376
                     self.categories.append(category)
354
 
377
 
355
-            # if no category is specified for this search, using user-defined default-configuration which (is stored in cookie)
378
+            # if no category is specified for this search,
379
+            # using user-defined default-configuration which
380
+            # (is stored in cookie)
356
             if not self.categories:
381
             if not self.categories:
357
                 cookie_categories = request.cookies.get('categories', '')
382
                 cookie_categories = request.cookies.get('categories', '')
358
                 cookie_categories = cookie_categories.split(',')
383
                 cookie_categories = cookie_categories.split(',')
360
                     if ccateg in categories:
385
                     if ccateg in categories:
361
                         self.categories.append(ccateg)
386
                         self.categories.append(ccateg)
362
 
387
 
363
-            # if still no category is specified, using general as default-category
388
+            # if still no category is specified, using general
389
+            # as default-category
364
             if not self.categories:
390
             if not self.categories:
365
                 self.categories = ['general']
391
                 self.categories = ['general']
366
 
392
 
367
-            # using all engines for that search, which are declared under the specific categories
393
+            # using all engines for that search, which are
394
+            # declared under the specific categories
368
             for categ in self.categories:
395
             for categ in self.categories:
369
                 self.engines.extend({'category': categ,
396
                 self.engines.extend({'category': categ,
370
                                      'name': x.name}
397
                                      'name': x.name}
371
                                     for x in categories[categ]
398
                                     for x in categories[categ]
372
-                                    if not x.name in self.blocked_engines)
399
+                                    if x.name not in self.blocked_engines)
373
 
400
 
374
     # do search-request
401
     # do search-request
375
     def search(self, request):
402
     def search(self, request):
386
         number_of_searches += 1
413
         number_of_searches += 1
387
 
414
 
388
         # set default useragent
415
         # set default useragent
389
-        #user_agent = request.headers.get('User-Agent', '')
416
+        # user_agent = request.headers.get('User-Agent', '')
390
         user_agent = gen_useragent()
417
         user_agent = gen_useragent()
391
 
418
 
392
         # start search-reqest for all selected engines
419
         # start search-reqest for all selected engines
400
             if self.pageno > 1 and not engine.paging:
427
             if self.pageno > 1 and not engine.paging:
401
                 continue
428
                 continue
402
 
429
 
403
-            # if search-language is set and engine does not provide language-support, skip
430
+            # if search-language is set and engine does not
431
+            # provide language-support, skip
404
             if self.lang != 'all' and not engine.language_support:
432
             if self.lang != 'all' and not engine.language_support:
405
                 continue
433
                 continue
406
 
434
 
412
             request_params['pageno'] = self.pageno
440
             request_params['pageno'] = self.pageno
413
             request_params['language'] = self.lang
441
             request_params['language'] = self.lang
414
 
442
 
415
-            # update request parameters dependent on search-engine (contained in engines folder)
443
+            # update request parameters dependent on
444
+            # search-engine (contained in engines folder)
416
             request_params = engine.request(self.query.encode('utf-8'),
445
             request_params = engine.request(self.query.encode('utf-8'),
417
                                             request_params)
446
                                             request_params)
418
 
447
 
431
                 request_params
460
                 request_params
432
             )
461
             )
433
 
462
 
434
-            # create dictionary which contain all informations about the request
463
+            # create dictionary which contain all
464
+            # informations about the request
435
             request_args = dict(
465
             request_args = dict(
436
                 headers=request_params['headers'],
466
                 headers=request_params['headers'],
437
                 hooks=dict(response=callback),
467
                 hooks=dict(response=callback),

+ 5
- 4
searx/utils.py View File

1
-#import htmlentitydefs
1
+# import htmlentitydefs
2
 from codecs import getincrementalencoder
2
 from codecs import getincrementalencoder
3
 from HTMLParser import HTMLParser
3
 from HTMLParser import HTMLParser
4
 from random import choice
4
 from random import choice
22
 
22
 
23
 def searx_useragent():
23
 def searx_useragent():
24
     return 'searx'
24
     return 'searx'
25
-    
25
+
26
+
26
 def highlight_content(content, query):
27
 def highlight_content(content, query):
27
 
28
 
28
     if not content:
29
     if not content:
67
         self.result.append(unichr(codepoint))
68
         self.result.append(unichr(codepoint))
68
 
69
 
69
     def handle_entityref(self, name):
70
     def handle_entityref(self, name):
70
-        #codepoint = htmlentitydefs.name2codepoint[name]
71
-        #self.result.append(unichr(codepoint))
71
+        # codepoint = htmlentitydefs.name2codepoint[name]
72
+        # self.result.append(unichr(codepoint))
72
         self.result.append(name)
73
         self.result.append(name)
73
 
74
 
74
     def get_text(self):
75
     def get_text(self):

+ 18
- 13
searx/webapp.py View File

71
 
71
 
72
 babel = Babel(app)
72
 babel = Babel(app)
73
 
73
 
74
-#TODO configurable via settings.yml
74
+# TODO configurable via settings.yml
75
 favicons = ['wikipedia', 'youtube', 'vimeo', 'soundcloud',
75
 favicons = ['wikipedia', 'youtube', 'vimeo', 'soundcloud',
76
             'twitter', 'stackoverflow', 'github']
76
             'twitter', 'stackoverflow', 'github']
77
 
77
 
146
 
146
 
147
     nonblocked_categories = set(chain.from_iterable(nonblocked_categories))
147
     nonblocked_categories = set(chain.from_iterable(nonblocked_categories))
148
 
148
 
149
-    if not 'categories' in kwargs:
149
+    if 'categories' not in kwargs:
150
         kwargs['categories'] = ['general']
150
         kwargs['categories'] = ['general']
151
         kwargs['categories'].extend(x for x in
151
         kwargs['categories'].extend(x for x in
152
                                     sorted(categories.keys())
152
                                     sorted(categories.keys())
153
                                     if x != 'general'
153
                                     if x != 'general'
154
                                     and x in nonblocked_categories)
154
                                     and x in nonblocked_categories)
155
 
155
 
156
-    if not 'selected_categories' in kwargs:
156
+    if 'selected_categories' not in kwargs:
157
         kwargs['selected_categories'] = []
157
         kwargs['selected_categories'] = []
158
         for arg in request.args:
158
         for arg in request.args:
159
             if arg.startswith('category_'):
159
             if arg.startswith('category_'):
168
     if not kwargs['selected_categories']:
168
     if not kwargs['selected_categories']:
169
         kwargs['selected_categories'] = ['general']
169
         kwargs['selected_categories'] = ['general']
170
 
170
 
171
-    if not 'autocomplete' in kwargs:
171
+    if 'autocomplete' not in kwargs:
172
         kwargs['autocomplete'] = autocomplete
172
         kwargs['autocomplete'] = autocomplete
173
 
173
 
174
     kwargs['method'] = request.cookies.get('method', 'POST')
174
     kwargs['method'] = request.cookies.get('method', 'POST')
202
             'index.html',
202
             'index.html',
203
         )
203
         )
204
 
204
 
205
-    search.results, search.suggestions, search.answers, search.infoboxes = search.search(request)
205
+    search.results, search.suggestions,\
206
+        search.answers, search.infoboxes = search.search(request)
206
 
207
 
207
     for result in search.results:
208
     for result in search.results:
208
 
209
 
209
         if not search.paging and engines[result['engine']].paging:
210
         if not search.paging and engines[result['engine']].paging:
210
             search.paging = True
211
             search.paging = True
211
 
212
 
212
-        # check if HTTPS rewrite is required 
213
+        # check if HTTPS rewrite is required
213
         if settings['server']['https_rewrite']\
214
         if settings['server']['https_rewrite']\
214
            and result['parsed_url'].scheme == 'http':
215
            and result['parsed_url'].scheme == 'http':
215
 
216
 
236
                         try:
237
                         try:
237
                             # TODO, precompile rule
238
                             # TODO, precompile rule
238
                             p = re.compile(rule[0])
239
                             p = re.compile(rule[0])
239
-                            
240
+
240
                             # rewrite url if possible
241
                             # rewrite url if possible
241
                             new_result_url = p.sub(rule[1], result['url'])
242
                             new_result_url = p.sub(rule[1], result['url'])
242
                         except:
243
                         except:
250
                             continue
251
                             continue
251
 
252
 
252
                         # get domainname from result
253
                         # get domainname from result
253
-                        # TODO, does only work correct with TLD's like asdf.com, not for asdf.com.de
254
+                        # TODO, does only work correct with TLD's like
255
+                        #  asdf.com, not for asdf.com.de
254
                         # TODO, using publicsuffix instead of this rewrite rule
256
                         # TODO, using publicsuffix instead of this rewrite rule
255
-                        old_result_domainname = '.'.join(result['parsed_url'].hostname.split('.')[-2:])
256
-                        new_result_domainname = '.'.join(new_parsed_url.hostname.split('.')[-2:])
257
+                        old_result_domainname = '.'.join(
258
+                            result['parsed_url'].hostname.split('.')[-2:])
259
+                        new_result_domainname = '.'.join(
260
+                            new_parsed_url.hostname.split('.')[-2:])
257
 
261
 
258
-                        # check if rewritten hostname is the same, to protect against wrong or malicious rewrite rules
262
+                        # check if rewritten hostname is the same,
263
+                        # to protect against wrong or malicious rewrite rules
259
                         if old_result_domainname == new_result_domainname:
264
                         if old_result_domainname == new_result_domainname:
260
                             # set new url
265
                             # set new url
261
                             result['url'] = new_result_url
266
                             result['url'] = new_result_url
262
 
267
 
263
-                    # target has matched, do not search over the other rules 
268
+                    # target has matched, do not search over the other rules
264
                     break
269
                     break
265
 
270
 
266
         if search.request_data.get('format', 'html') == 'html':
271
         if search.request_data.get('format', 'html') == 'html':
429
         for pd_name, pd in request.form.items():
434
         for pd_name, pd in request.form.items():
430
             if pd_name.startswith('category_'):
435
             if pd_name.startswith('category_'):
431
                 category = pd_name[9:]
436
                 category = pd_name[9:]
432
-                if not category in categories:
437
+                if category not in categories:
433
                     continue
438
                     continue
434
                 selected_categories.append(category)
439
                 selected_categories.append(category)
435
             elif pd_name == 'locale' and pd in settings['locales']:
440
             elif pd_name == 'locale' and pd in settings['locales']: